コード例 #1
0
ファイル: Console.php プロジェクト: spire-framework/spire
 /**
  * Runs the migrations.
  *
  * @param  array  $arguments  Command arguments.
  * @return string
  */
 public function run(array $arguments = []) : string
 {
     // Get the uninstalled modules.
     $migrations = Model::where('installed', '=', '0')->orderBy('created_at', 'desc')->all();
     // Run the migrations.
     foreach ($migrations as $migration) {
         // Get the class name.
         $name = substr($migration->migration, 0, -4);
         $name = sprintf('\\Modules\\%s\\Migration\\%s', $migration->module, $name);
         // If migration exists, run it.
         if (is_file(path('modules', $migration->module) . 'Migration/' . $migration->migration)) {
             // Instantiate the migration.
             $class = new $name();
             // Does the up method exist?
             if (method_exists($class, 'up')) {
                 // Run the migrations up method.
                 $class->up();
                 // Record the migration as installed.
                 $migration->installed = 1;
                 $migration->save();
                 // Send output.
                 Output::send(sprintf('%s-%s Installed.', $migration->module, $migration->migration));
             }
         }
     }
     return 'Migrations installed';
 }
コード例 #2
0
ファイル: Console.php プロジェクト: spire-framework/spire
 /**
  * Initializes the console.
  *
  * @return void
  */
 public static function initialize()
 {
     // Startup Spire.
     Spire::start();
     // Get the arguments.
     $arguments = $_SERVER['argv'] ?? [];
     // Clear the executed file from the arguments.
     array_shift($arguments);
     // Get the command and task.
     list($command, $task) = explode('::', $arguments[0]);
     // Get the final arguments by removing the command.
     array_shift($arguments);
     // Do we have a valid command?
     $class = static::$commands[$command] ?? false;
     // If so run it.
     if ($class) {
         $console = new $class();
         $message = $console->execute((string) $task, $arguments);
         if (is_string($message)) {
             Output::send($message);
         }
     }
     // Close Spire.
     Spire::close();
 }