Browse Source

moved include file logic to separate method

tags/2.0.12
Carsten Brandt 7 years ago
parent
commit
6ec6f8d76c
No known key found for this signature in database
GPG Key ID: BE4F41DE1DEEEED0
  1. 5
      docs/guide/db-migrations.md
  2. 17
      framework/console/controllers/BaseMigrateController.php
  3. 18
      framework/console/controllers/MigrateController.php

5
docs/guide/db-migrations.md

@ -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.

17
framework/console/controllers/BaseMigrateController.php

@ -717,6 +717,21 @@ abstract class BaseMigrateController extends Controller
*/
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) {
if (is_array($this->migrationPath)) {
@ -732,8 +747,6 @@ abstract class BaseMigrateController extends Controller
require_once($file);
}
}
return new $class();
}
/**

18
framework/console/controllers/MigrateController.php

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

Loading…
Cancel
Save