protected function executeCommand($command) { // Cache can not be warmed up as classes can not be redefined during one request if (preg_match('/^cache:clear/', $command)) { $command .= ' --no-warmup'; } $input = new StringInput($command); $input->setInteractive(false); $output = new StringOutput(); $formatter = $output->getFormatter(); $formatter->setDecorated(true); $output->setFormatter(new HtmlOutputFormatterDecorator($formatter)); $application = $this->getApplication($input); $application->setAutoExit(false); // Some commands (i.e. doctrine:query:dql) dump things out instead of returning a value ob_start(); $errorCode = $application->run($input, $output); // So, if the returned output is empty if (!($result = $output->getBuffer())) { $result = ob_get_contents(); // We replace it by the catched output } ob_end_clean(); return array('input' => $command, 'output' => $result, 'environment' => $this->getKernel($input)->getEnvironment(), 'error_code' => $errorCode); }
public function execAction($_format = 'json') { chdir($this->container->getParameter('kernel.root_dir') . '/..'); $request = $this->get('request'); $command = $request->request->get('command'); # Cache can not be warmed up as classes can not be redefined during one request if (preg_match('/^cache:clear/', $command)) { $command .= ' --no-warmup'; } $input = new StringInput($command); $input->setInteractive(FALSE); $output = new StringOutput(); $formatter = $output->getFormatter(); $formatter->setDecorated(true); $formatter->setStyle('error', new HtmlOutputFormatterStyle('white', 'red')); $formatter->setStyle('info', new HtmlOutputFormatterStyle('green')); $formatter->setStyle('comment', new HtmlOutputFormatterStyle('yellow')); $formatter->setStyle('question', new HtmlOutputFormatterStyle('black', 'cyan')); $output->setFormatter(new HtmlOutputFormatterDecorator($formatter)); $application = $this->getApplication($input); $application->setAutoExit(FALSE); // Some commands (i.e. doctrine:query:dql) dump things out instead of returning a value // Looks like a hack, but no way to do this differently ob_start(); $application->run($input, $output); $dumped = ob_get_contents(); // We catch it and concatenate it to the output ob_end_clean(); return $this->render('CoreSphereConsoleBundle:Console:result.' . $_format . '.twig', array('input' => $command, 'output' => $output->getBuffer() . $dumped, 'environment' => $this->getKernel($input)->getEnvironment())); }
/** * {@inheritdoc} */ public function execute($commandString) { $input = new StringInput($commandString); $output = new StringOutput(); $application = $this->getApplication($input); $formatter = $output->getFormatter(); $kernel = $application->getKernel(); chdir($kernel->getRootDir() . '/..'); $input->setInteractive(false); $formatter->setDecorated(true); $output->setFormatter(new HtmlOutputFormatterDecorator($formatter)); $application->setAutoExit(false); $errorCode = $application->run($input, $output); return ['input' => $commandString, 'output' => $output->getBuffer(), 'environment' => $kernel->getEnvironment(), 'error_code' => $errorCode]; }