diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 1756a9a535..3a9ac53e44 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -76,7 +76,7 @@ Yii Framework 2 Change Log - Chg #14286: Used primary inputmask package name instead of an alias (samdark) - Chg #14321: `yii\widgets\MaskedInput` is now registering its JavaScript `clientOptions` initialization code in head section (DaveFerger) - Chg #14487: Changed i18n message error to warning (dmirogin) - +- Enh #14864: Ability to use dependencies in constructor of migrations (vtvz) 2.0.12 June 05, 2017 -------------------- diff --git a/framework/console/controllers/BaseMigrateController.php b/framework/console/controllers/BaseMigrateController.php index 557c8a50e0..8723fa8911 100644 --- a/framework/console/controllers/BaseMigrateController.php +++ b/framework/console/controllers/BaseMigrateController.php @@ -14,6 +14,7 @@ use yii\base\NotSupportedException; use yii\console\Controller; use yii\console\Exception; use yii\console\ExitCode; +use yii\db\MigrationInterface; use yii\helpers\Console; use yii\helpers\FileHelper; @@ -760,10 +761,13 @@ abstract class BaseMigrateController extends Controller protected function createMigration($class) { $this->includeMigrationFile($class); - $migration = new $class(); + + /** @var MigrationInterface $migration */ + $migration = Yii::createObject($class); if ($migration instanceof BaseObject && $migration->canSetProperty('compact')) { $migration->compact = $this->compact; } + return $migration; } diff --git a/framework/console/controllers/MigrateController.php b/framework/console/controllers/MigrateController.php index 63c62cc073..519b16737d 100644 --- a/framework/console/controllers/MigrateController.php +++ b/framework/console/controllers/MigrateController.php @@ -185,7 +185,12 @@ class MigrateController extends BaseMigrateController protected function createMigration($class) { $this->includeMigrationFile($class); - return new $class(['db' => $this->db, 'compact' => $this->compact]); + + return Yii::createObject([ + 'class' => $class, + 'db' => $this->db, + 'compact' => $this->compact, + ]); } /**