Пример #1
0
 /**
  * Constructor.
  * 
  * @param AbstractApplication $pplication Application to which this console belongs.
  */
 public function __construct(AbstractApplication $application, LoggerInterface $logger = null)
 {
     $this->application = $application;
     $this->logger = $logger;
     // initialize Symfony Console component
     $this->consoleApplication = new ConsoleApplication($application->getName() . ' (Splot Console)', $application->getVersion());
     $definition = $this->consoleApplication->getDefinition();
     $definition->addOption(new InputOption('env', null, InputOption::VALUE_REQUIRED, 'Environment in which to run.'));
     $definition->addOption(new InputOption('no-debug', null, InputOption::VALUE_NONE, 'Turn off debug mode.'));
     // now gather all commands from the application
     foreach ($this->application->getModules() as $module) {
         $this->readModuleCommands($module);
     }
 }
Пример #2
0
 /**
  * Constructor.
  *
  * @param Application $application Application for this router.
  * @param CacheInterface $cache Cache in which routes definitions will be stored.
  * @param boolean $cacheEnabled [optional] Whether or not the cache is enabled. Default: `true`.
  * @param string $host [optional] Host to use when generating full URL's. Default: `localhost`.
  * @param string $protocol [optional] Protocol to use when generating full URL's. Default: `http://`.
  * @param int $port [optional] Port to use when generating full URL's. Default: `80`.
  */
 public function __construct(AbstractApplication $application, CacheInterface $cache, $cacheEnabled = true, $host = 'localhost', $protocol = 'http://', $port = 80)
 {
     $this->cache = $cache;
     $this->cache->setEnabled($cacheEnabled);
     $this->setHost($host);
     $this->setProtocol($protocol);
     $this->setPort($port);
     // read all routes from cache and if there aren't any then read them from application modules and write to cache
     $router = $this;
     $this->routes = $this->cache->get('routes', 0, function () use($router, $application) {
         foreach ($application->getModules() as $module) {
             $router->readModuleRoutes($module);
         }
         return $router->getRoutes();
     });
 }
Пример #3
0
 /**
  * Runs the application in context of the given mode and using the given runner function.
  *
  * The last argument is a callback that will be invoked by this method and it should contain
  * execution logic specific to the given mode.
  *
  * Returns whatever the runner returns (which should be a result of running the application).
  * 
  * @param  AbstractApplication $application Application to be ran.
  * @param  int                 $mode        Mode in which the application should be ran.
  *                                          One of the `Framework::MODE_*` constants.
  * @param  callable            $runner      Closure that is responsible for actually running
  *                                          the application in appropriate mode.
  * @return mixed
  */
 protected function doRunApplication(AbstractApplication $application, $mode, $runner)
 {
     $timer = new Timer();
     $container = $application->getContainer();
     // container can now know in what mode its running
     $container->setParameter('mode', $mode);
     // run modules and the app
     foreach ($application->getModules() as $module) {
         $module->run();
     }
     $application->run();
     // run using the passed runner
     $result = call_user_func($runner);
     // log benchmark data
     $time = $timer->stop();
     $memory = $timer->getMemoryUsage();
     $container->get('splot.logger')->debug('Application run phase in mode "{mode}" finished in {time} ms and used {memory} memory.', array('mode' => self::modeName($mode), 'env' => $container->getParameter('env'), 'debug' => $container->getParameter('debug'), 'time' => $time, 'memory' => StringUtils::bytesToString($memory), '@stat' => 'splot.run.' . self::modeName($mode), '@time' => $time, '@memory' => $memory));
     return $result;
 }