示例#1
0
 public function run()
 {
     switch ($this->mainArgv) {
         case 'generate':
             $gen = new Generators\Generator($this);
             $gen->parseCmd();
             break;
         case 'assets':
             $rules = ['assets' => '', 'action' => ''];
             $opts = new Zend\Console\Getopt($rules);
             $argv = $opts->getArguments();
             if (empty($argv[1])) {
                 $this->terminate("Missing argument 2");
             }
             \Rails::resetConfig('production');
             switch ($argv[1]) {
                 case 'compile:all':
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileAll();
                     break;
                 case strpos($argv[1], 'compile:') === 0:
                     $parts = explode(':', $argv[1]);
                     if (empty($parts[1])) {
                         $this->terminate("Missing asset name to compile");
                     }
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileFile($parts[1]);
                     break;
                 default:
                     $this->terminate("Unknown action for assets");
                     break;
             }
             break;
         case 'routes':
             $routes = $this->createRoutes();
             $rules = ['routes' => '', 'f-s' => ''];
             $opts = new Zend\Console\Getopt($rules);
             if ($filename = $opts->getOption('f')) {
                 if (true === $filename) {
                     $logFile = \Rails::config()->paths->log->concat('routes.log');
                 } else {
                     $logFile = \Rails::root() . '/' . $filename;
                 }
                 file_put_contents($logFile, $routes);
             }
             $this->write($routes);
             break;
             /**
              * Install database.
              */
         /**
          * Install database.
          */
         case 'db:create':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->loadSchema();
             break;
             /**
              * Run all/pending migrations.
              * Creates migrations table as well.
              */
         /**
          * Run all/pending migrations.
          * Creates migrations table as well.
          */
         case 'db:migrate':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->run();
             break;
             /**
              * Runs seeds.
              */
         /**
          * Runs seeds.
          */
         case 'db:seed':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->runSeeds();
             break;
         case 'db:schema:dump':
             $dumper = new \Rails\ActiveRecord\Schema\Dumper(\Rails\ActiveRecord\ActiveRecord::connection());
             $dumper->export(\Rails::root() . '/db/schema.sql');
             break;
     }
 }
示例#2
0
<?php

use Zend\Console\ColorInterface as Color;
/**
 * Boot Rails
 */
require __DIR__ . '/config/boot.php';
/**
 * Create console and migrator
 */
$c = new Rails\Console\Console();
$migrator = new Rails\ActiveRecord\Migration\Migrator();
/**
 * Show splash
 */
$txColor = Color::LIGHT_WHITE;
$bgColor = Color::GREEN;
$c->put();
$c->put("====================", $txColor, $bgColor);
$c->put(" MyImouto installer ", $txColor, $bgColor);
$c->put("====================", $txColor, $bgColor);
$c->put();
/**
 * Get data for admin account
 */
$c->put("Admin account", null, Color::BLUE);
$c->put("Please enter a name and password for the admin account.");
$c->write("Note: ", Color::RED);
$c->put("the password will be shown.");
list($adminName, $adminPass) = getAdminData($c);
/**