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

@ -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]);
}