예제 #1
0
 /**
  * Executes the command.
  *
  * @access  public
  * @param   \mako\application\Application  $application  Application instance
  * @param   \mako\file\FileSystem          $fileSystem   File system instance
  * @param   string                         $package      Package name
  * @param   string                         $description  Migration description
  */
 public function execute(Application $application, FileSystem $fileSystem, $package = null, $description = null)
 {
     // Get file path and namespace
     if (empty($package)) {
         $namespace = $application->getNamespace() . '\\migrations';
         $path = $application->getPath() . '/migrations/';
     } else {
         $package = $application->getPackage($package);
         $namespace = $package->getClassNamespace() . '\\migrations';
         $path = $package->getPath() . '/src/migrations/';
     }
     $path .= 'Migration_' . ($version = gmdate('YmdHis')) . '.php';
     // Create migration
     $description = str_replace("'", "\\'", $description);
     $search = ['{{namespace}}', '{{version}}', '{{description}}'];
     $replace = [$namespace, $version, $description];
     $migration = str_replace($search, $replace, $fileSystem->getContents(__DIR__ . '/resources/migration.template'));
     try {
         $fileSystem->putContents($path, $migration);
     } catch (Exception $e) {
         $this->error('Failed to create migration. Make sure that the migrations directory is writable.');
         return;
     }
     $this->write(vsprintf('Migration created at [ %s ].', [$path]));
 }
예제 #2
0
 /**
  * Returns all application migrations.
  *
  * @access  protected
  * @return  array
  */
 protected function findApplicationMigrations()
 {
     $migrations = [];
     foreach ($this->fileSystem->glob($this->application->getPath() . '/migrations/*.php') as $migration) {
         $migrations[] = (object) ['package' => null, 'version' => $this->getBasename($migration)];
     }
     return $migrations;
 }
예제 #3
0
 /**
  * Executes the command.
  *
  * @access  public
  * @param   \mako\application\Application  $application  Application instance
  * @param   int                            $port         Port
  * @param   string                         $address      Address
  * @param   null|string                    $docroot      Document root
  */
 public function execute(Application $application, $port = 8000, $address = 'localhost', $docroot = null)
 {
     $docroot = $docroot ?: dirname($application->getPath()) . '/public';
     $host = $address === '0.0.0.0' ? gethostbyname(gethostname()) : $address;
     $message = 'Starting <green>Mako</green> development server at ';
     $message .= '<underlined>http://' . $host . ':' . $port . '</underlined> ';
     $message .= '<yellow>(ctrl+c to stop)</yellow> ...';
     $this->write($message);
     passthru(PHP_BINDIR . '/php -S ' . $address . ':' . $port . ' -t ' . $docroot . ' ' . __DIR__ . '/router.php');
 }
 /**
  * Executes the command.
  *
  * @access  public
  * @param   \mako\application\Application  $application  Application instance
  * @param   \mako\file\FileSystem          $fileSystem   File system instance
  */
 public function execute(Application $application, FileSystem $fileSystem)
 {
     $configFile = $application->getPath() . '/config/application.php';
     if (!$fileSystem->isWritable($configFile)) {
         $this->error('Unable to generate a new secret. Make sure that the [ app/config/application.php ] file is writable.');
         return;
     }
     if (function_exists('openssl_random_pseudo_bytes')) {
         $secret = bin2hex(openssl_random_pseudo_bytes(32));
     } else {
         $secret = str_replace(['"', '\''], ['|', '/'], Str::random(Str::ALNUM . Str::SYMBOLS, 64));
     }
     $contents = $fileSystem->getContents($configFile);
     $contents = preg_replace('/\'secret\'(\\s*)=>(\\s*)\'(.*)\',/', '\'secret\'$1=>$2\'' . $secret . '\',', $contents);
     $fileSystem->putContents($configFile, $contents);
     $this->write('A new application secret has been generated.');
 }