示例#1
0
 /**
  * @param Input  $input
  * @param Output $output
  * @return int
  */
 public function execute(Input $input, Output $output)
 {
     $connection = $input->getArgument('connection');
     if (empty($connection)) {
         $connection = 'read';
     }
     $bundle = $input->getOption('bundle');
     $driver = $this->getDriver($connection);
     $parser = new SchemaParser($driver, true);
     if (null !== $bundle) {
         $bundle = $this->getContainer()->singleton('kernel')->getBundle($bundle);
         $path = $bundle->getRootPath() . '/ORM/' . ucfirst($this->rename($driver->getDbName()));
         $namespace = $bundle->getNamespace() . '\\ORM\\' . ucfirst($this->rename($driver->getDbName()));
         $parser->getSchemaReflex()->reflex($path, $namespace);
         $output->writeln('<notice>' . $bundle->getName() . '</notice>');
         $output->writeln('  Reflex to ' . $path . '... <success>[OK]</success>');
         return 0;
     }
     $bundles = $this->getContainer()->singleton('kernel')->getBundles();
     foreach ($bundles as $bundle) {
         $output->writeln('<notice>' . $bundle->getName() . '</notice>');
         $path = $bundle->getRootPath() . '/ORM/' . ucfirst($this->rename($driver->getDbName()));
         $namespace = $bundle->getNamespace() . '\\ORM\\' . ucfirst($this->rename($driver->getDbName()));
         $parser->getSchemaReflex()->reflex($path, $namespace);
         $output->writeln('  Reflex to ' . $path . '... <success>[OK]</success>');
     }
     return 0;
 }
 /**
  * @param Input $input
  * @param Output $output
  * @return int
  */
 public function execute(Input $input, Output $output)
 {
     $path = $this->getContainer()->get('kernel')->getRootPath() . '/storage/templates';
     if (!file_exists($path)) {
         $output->writeln('done');
         return true;
     }
     $recursion = null;
     $recursion = function ($path) use(&$recursion) {
         $fp = opendir($path);
         while ($file = readdir($fp)) {
             if ('.' === $file || '..' === $file) {
                 continue;
             }
             $file = "{$path}/{$file}";
             if (is_dir($file)) {
                 $recursion($file);
                 rmdir($file);
             } else {
                 unlink($file);
             }
         }
         closedir($fp);
     };
     $output->write('Clearing template cache ... ');
     try {
         $recursion($path);
     } catch (\Exception $e) {
         $output->writeln('<error>failed</error>');
         return 0;
     }
     $output->writeln('<success>success</success>');
     return 1;
 }
示例#3
0
 public function execute(Input $input, Output $output)
 {
     $kernel = $this->getContainer()->singleton('kernel');
     $caching = $kernel->getRootPath() . DIRECTORY_SEPARATOR . RouteCacheCommand::CACHE_NAME;
     $routing = $this->getContainer()->singleton('kernel.routing');
     // Init caching file.
     file_put_contents($caching, '<?php' . PHP_EOL);
     foreach ($routing as $route) {
         $default = array() === $route->getDefaults() ? '[]' : (function () use($route) {
             $arr = [];
             foreach ($route->getDefaults() as $name => $value) {
                 $arr[] = "'{$name}' => '{$value}'";
             }
             return '[' . implode(',', $arr) . ']';
         })();
         $requirements = array() === $route->getRequirements() ? '[]' : (function () use($route) {
             $arr = [];
             foreach ($route->getRequirements() as $name => $value) {
                 $arr[] = "'{$name}' => '{$value}'";
             }
             return '[' . implode(',', $arr) . ']';
         })();
         $line = "Routes::" . strtolower($route->getMethod()) . "('{$route->getName()}', '{$route->getPath()}', '{$route->getCallback()}', {$default}, {$requirements})";
         if (null != $route->getScheme() && $route->getScheme() != ['http']) {
             $line .= '->setScheme(\'' . $route->getScheme() . '\')';
         }
         if (null != $route->getFormats()) {
             $line .= '->setFormats([\'' . implode('\',\'', $route->getFormats() ?? []) . '\'])';
         }
         file_put_contents($caching, $line . ';' . PHP_EOL, FILE_APPEND);
     }
     $output->writeln('Caching to ' . $caching . '......  <success>[OK]</success>');
     return 0;
 }
示例#4
0
 /**
  * @param Input $input
  * @param Output $output
  * @return int
  */
 public function execute(Input $input, Output $output)
 {
     $kernel = $this->getContainer()->get('kernel');
     $config = new Config();
     $prod = $kernel->getRootPath() . '/config/config_prod.php';
     if (file_exists($prod)) {
         $config->load($prod);
     }
     foreach ($kernel->getBundles() as $bundle) {
         $bundle->registerConfiguration($config, AppKernel::ENV_PROD);
     }
     $caching = $kernel->getRootPath() . DIRECTORY_SEPARATOR . ConfigCacheCommand::CACHE_NAME;
     file_put_contents($caching, '<?php return ' . var_export($config->all(), true) . ';');
     $output->writeln('Caching to ' . $caching . '...... <success>[OK]</success>');
 }
示例#5
0
 /**
  * @param Input  $input
  * @param Output $output
  * @return int
  */
 public function execute(Input $input, Output $output)
 {
     $connection = $input->getArgument('connection');
     if (empty($connection)) {
         $connection = 'read';
     }
     $bundle = $input->getOption('bundle');
     $loader = new FixtureLoader($this->getDriver($connection));
     $fixtures = $this->scanFixtures($bundle);
     foreach ($fixtures as $name => $fixture) {
         $fixture = new $fixture();
         if ($fixture instanceof FixtureInterface) {
             $loader->registerFixture($fixture);
             $output->writeln(sprintf('Register "%s" schema. <success>[OK]</success>', $name));
         }
     }
     $loader->runSchema();
 }
 /**
  * @param Input $input
  * @param Output $output
  * @return void
  */
 public function execute(Input $input, Output $output)
 {
     try {
         $bundle = $input->getArgument('bundle');
     } catch (\Exception $e) {
         $output->writeln('<error>Bundle name is empty or null. Please you try again.</error>');
         exit;
     }
     if (empty($bundle)) {
         $output->writeln('<error>Bundle name is empty or null. Please you try again.</error>');
         exit;
     }
     $bundle = str_replace(':', DIRECTORY_SEPARATOR, $bundle) . 'Bundle';
     $bundle = implode(DIRECTORY_SEPARATOR, array_map(function ($v) {
         return ucfirst($v);
     }, explode(DIRECTORY_SEPARATOR, $bundle)));
     $source = $this->getContainer()->singleton('kernel')->getRootPath() . '/../src';
     $this->builderStructure($source, $bundle, str_replace(DIRECTORY_SEPARATOR, '', $bundle));
     $output->writeln('Building in ' . $source . '  <success>[OK]</success>');
 }
 /**
  * @param Input $input
  * @param Output $output
  * @throws \Exception
  * @return void
  */
 public function execute(Input $input, Output $output)
 {
     $kernel = $this->getContainer()->singleton('kernel');
     $bundles = $kernel->getBundles();
     $web = 'public/bundles';
     $targetRootDir = $kernel->getRootPath() . '/../' . $web;
     $output->writeln('Trying to install assets as symbolic links.');
     foreach ($bundles as $bundle) {
         $originDir = $bundle->getRootPath() . DIRECTORY_SEPARATOR . 'Resources/assets';
         if (!file_exists($originDir)) {
             continue;
         }
         $targetDir = $targetRootDir . DIRECTORY_SEPARATOR . strtolower($bundle->getShortName());
         try {
             $this->symlink($originDir, $targetDir);
             $output->write('Installing assets for ');
             $output->write(sprintf('<success>%s</success>', $bundle->getName()));
             $output->write(' into ');
             $output->writeln($web . DIRECTORY_SEPARATOR . sprintf('<success>%s</success>', strtolower($bundle->getShortName())));
         } catch (\Exception $e) {
             throw $e;
         }
     }
 }
示例#8
0
 /**
  * @param Input $input
  * @param Output $output
  * @return int
  */
 public function execute(Input $input, Output $output)
 {
     $output->writeln(sprintf('Running (%s) with PHP %s on %s / %s', date('Y-m-d H:i:s'), PHP_VERSION, PHP_OS, php_uname('r')));
     $output->writeln(sprintf('FastD Kernel version <info>%s</info>', AppKernel::VERSION));
     $output->writeln(sprintf('Environment <info>"%s"</info>', $this->getContainer()->get('kernel')->getEnvironment()));
 }
示例#9
0
 /**
  * Format route output to command line.
  *
  * @param Route  $route
  * @param Output $output
  * @param        $type
  */
 public function formatOutput(Route $route, Output $output, $type = self::STYLE_DETAIL)
 {
     switch ($type) {
         case self::STYLE_DETAIL:
             $output->write('Route [');
             $output->write('<success>"' . $route->getName() . '"</success>');
             $output->writeln(']');
             $output->writeln("Path:\t\t" . str_replace('//', '/', $route->getPath()));
             $output->writeln("Method:\t\t" . $route->getMethod());
             $output->writeln("Format:\t\t" . implode(', ', $route->getFormats()));
             $output->writeln("Callback:\t" . (is_callable($route->getCallback()) ? 'Closure' : $route->getCallback()));
             $output->writeln("Defaults:\t" . implode(', ', $route->getDefaults()));
             $output->writeln("Requirements:\t" . implode(', ', $route->getRequirements()));
             $output->writeln("Path-Regex:\t" . $route->getPathRegex());
             $output->writeln('');
             break;
         case self::STYLE_LIST:
         default:
             $name = $route->getName();
             $method = $route->getMethod();
             $schema = $route->getScheme() ?? 'http';
             $path = $route->getPath();
             $output->write($name . str_repeat(' ', 25 - strlen($name)));
             $output->write($method . str_repeat(' ', 15 - strlen($method)));
             $output->write($schema . str_repeat(' ', 15 - strlen($schema)));
             $output->writeln($path);
     }
     return;
 }