moved include file logic to separate method

This commit is contained in:
Carsten Brandt
2017-06-02 13:32:02 +02:00
parent 5288577221
commit 6ec6f8d76c
3 changed files with 19 additions and 21 deletions

View File

@ -835,9 +835,10 @@ The migration command comes with a few command-line options that can be used to
When this is `true`, the user will be prompted before the command performs certain actions.
You may want to set this to `false` if the command is being used in a background process.
* `migrationPath`: string (defaults to `@app/migrations`), specifies the directory storing all migration
* `migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration
class files. This can be specified as either a directory path or a path [alias](concept-aliases.md).
Note that the directory must exist, or the command may trigger an error.
Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be
specified for loading migrations from multiple sources.
* `migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing
migration history information. The table will be automatically created by the command if it does not exist.

View File

@ -716,6 +716,21 @@ abstract class BaseMigrateController extends Controller
* @return \yii\db\MigrationInterface the migration instance
*/
protected function createMigration($class)
{
$this->includeMigrationFile($class);
return new $class();
}
/**
* Includes the migration file for a given migration class name.
*
* This function will do nothing on namespaced migrations, which are loaded by
* autoloading automatically. It will include the migration file, by searching
* [[migrationPath]] for classes without namespace.
* @param string $class the migration class name.
* @since 2.0.12
*/
protected function includeMigrationFile($class)
{
$class = trim($class, '\\');
if (strpos($class, '\\') === false) {
@ -732,8 +747,6 @@ abstract class BaseMigrateController extends Controller
require_once($file);
}
}
return new $class();
}
/**

View File

@ -182,23 +182,7 @@ class MigrateController extends BaseMigrateController
*/
protected function createMigration($class)
{
$class = trim($class, '\\');
if (strpos($class, '\\') === false) {
if (is_array($this->migrationPath)) {
foreach($this->migrationPath as $path) {
$file = $path . DIRECTORY_SEPARATOR . $class . '.php';
if (is_file($file)) {
require_once($file);
break;
}
}
} else {
$file = $this->migrationPath . DIRECTORY_SEPARATOR . $class . '.php';
require_once($file);
}
}
$this->includeMigrationFile($class);
return new $class(['db' => $this->db]);
}