/** * 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); } }
/** * Warms up the given application by bootstrapping and configuring it and its' * dependency injection container. * * Returns the application's DI container for convenience. * * @param AbstractApplication $application Application to be ran. * @param string $env [optional] Environment in which the application should be ran. Default: `dev`. * @param boolean $debug [optional] Should application be ran in debug mode? Default: `true`. * @return ContainerInterface */ public function warmup(AbstractApplication $application, $env = 'dev', $debug = true) { $timer = new Timer(); // verify the application $applicationName = $application->getName(); if (!is_string($applicationName) || empty($applicationName)) { throw new \RuntimeException('You have to specify an application name inside the Application class by defining protected property "$name".'); } if (!StringUtils::isClassName($applicationName)) { throw new \RuntimeException('Application name must conform to variable naming rules and therefore can only start with a letter and only contain letters, numbers and _, "' . $applicationName . '" given.'); } $this->bootstrapApplication($application, $env, $debug); $container = $this->configureApplication($application, $env, $debug); $container->set('splot.timer', $timer); return $container; }