Пример #1
0
 /**
  * Executes a command by parsing all the input options and arguments and passing them to the command.
  * 
  * @param string $name Name of the command to call.
  * @param InputInterface $input Input.
  * @param OutputInterface $ouput Output.
  */
 public function exec($name, InputInterface $input, OutputInterface $output)
 {
     if (!isset($this->commands[$name])) {
         throw new NotFoundException('The command "' . $name . '" was not found in the list of registered commands.');
     }
     $commandInfo = $this->commands[$name];
     $commandClass = $commandInfo['class'];
     $consoleCommand = $commandInfo['command'];
     // instantiate the command with appropriate DI
     $command = new $commandClass($this->application->getContainer(), $input, $output, $consoleCommand->getHelperSet());
     // parse options
     $command->setOptions($input->getOptions());
     // parse arguments
     $arguments = array();
     foreach ($input->getArguments() as $key => $argument) {
         // if key is command then ignore it
         if ($key === 'command') {
             continue;
         }
         $arguments[] = $argument;
     }
     // call!
     call_user_func_array(array($command, 'execute'), $arguments);
 }
Пример #2
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;
 }