Example #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]));
 }
Example #2
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.');
 }
Example #4
0
 /**
  * Returns a migration instance.
  *
  * @access  protected
  * @param   StdClass                             $migration  Migration object
  * @return  \mako\database\migrations\Migration
  */
 protected function resolve($migration)
 {
     if (empty($migration->package)) {
         $namespace = $this->application->getNamespace(true) . '\\migrations\\';
     } else {
         $namespace = $this->application->getPackage($migration->package)->getClassNamespace(true) . '\\migrations\\';
     }
     return $this->container->get($namespace . $migration->version);
 }
 /**
  * Executes the command.
  *
  * @access  public
  * @param   \mako\application\Application  $application  Application instance
  */
 public function execute(Application $application)
 {
     // Build table rows
     foreach ($application->getRouteCollection()->getRoutes() as $route) {
         // Normalize action name
         $action = $route->getAction() instanceof Closure ? 'Closure' : $route->getAction();
         // Normalize before filter names
         $beforeFilters = [];
         foreach ($route->getBeforeFilters() as $filter) {
             $beforeFilters[] = $filter;
         }
         // Normalize after filter names
         $afterFilters = [];
         foreach ($route->getAfterFilters() as $filter) {
             $afterFilters[] = $filter;
         }
         // Build table row
         $routes[] = [$route->getRoute(), implode(', ', $route->getMethods()), $action, implode(', ', $beforeFilters), implode(', ', $afterFilters), (string) $route->getName()];
     }
     // Draw table
     $headers = ['<green>Route</green>', '<green>Allowed methods</green>', '<green>Action</green>', '<green>Before filters</green>', '<green>After filters</green>', '<green>Name</green>'];
     $this->table($headers, $routes);
 }
Example #6
0
 /**
  * Returns the connection of the model.
  *
  * @access  public
  * @return  \mako\database\connections\Connection
  */
 public function getConnection()
 {
     if (empty(static::$connectionManager)) {
         static::$connectionManager = Application::instance()->getContainer()->get('database');
     }
     return static::$connectionManager->connection($this->connectionName);
 }