/**
  * @param array $input
  *
  * @return integer
  */
 public function run($input = array())
 {
     $this->input = new ArrayInput((array) $input);
     $this->input->setInteractive(false);
     $this->output = new StreamOutput(fopen('php://memory', 'r+', false));
     $inputStream = $this->getInputStream();
     rewind($inputStream);
     $this->application->getHelperSet()->get('dialog')->setInputStream($inputStream);
     return $this->application->doRun($this->input, $this->output);
 }
Exemple #2
0
 /**
  * @param string                        $input
  * @param int                           $verbosity
  * @param OutputFormatterInterface|null $formatter
  */
 public function __construct($input = '', $verbosity = StreamOutput::VERBOSITY_NORMAL, OutputFormatterInterface $formatter = null)
 {
     $input = new StringInput($input);
     $input->setInteractive(false);
     $output = new StreamOutput(fopen('php://memory', 'rw'), $verbosity, $formatter ? $formatter->isDecorated() : false, $formatter);
     parent::__construct($input, $output, new HelperSet(array()));
 }
 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()));
 }
 private function runCommandsCommand(OutputInterface $output = null)
 {
     $input = new StringInput('modera:upgrade --run-commands ' . __DIR__ . '/versions.json');
     $input->setInteractive(false);
     $app = $this->getApplication();
     $result = $app->run($input, $output ?: new NullOutput());
     $this->assertEquals(0, $result);
 }
 /**
  * @param string $input
  * @param array  $options
  *
  * @return integer
  */
 public function run($input, array $options = array())
 {
     if (isset($options['interactive']) && $options['interactive']) {
         $this->input = new InteractiveStringInput($input);
     } else {
         $this->input = new StringInput($input);
         $this->input->setInteractive(false);
     }
     $this->output = new StreamOutput(fopen('php://memory', 'w', false));
     if (isset($options['decorated'])) {
         $this->output->setDecorated($options['decorated']);
     }
     if (isset($options['verbosity'])) {
         $this->output->setVerbosity($options['verbosity']);
     }
     $inputStream = $this->getInputStream();
     rewind($inputStream);
     $this->application->getHelperSet()->get('dialog')->setInputStream($inputStream);
     return $this->application->run($this->input, $this->output);
 }
 /**
  * Run an Artisan console command by name.
  *
  * @param string $command
  * @param array  $parameters
  *
  * @return int
  */
 public function call($command, array $parameters = [])
 {
     $this->lastOutput = $this->getBufferedOutput();
     $this->setCatchExceptions(false);
     $command = $command . '' . implode(' ', $parameters);
     $input = new StringInput($command);
     $input->setInteractive(false);
     $result = $this->run($input, $this->lastOutput);
     $this->setCatchExceptions(true);
     return $result;
 }
 /**
  * handle.
  *
  * @throws \InvalidArgumentException
  */
 public function fire()
 {
     $command = $this->option('command');
     if ($this->needForce($command) === true) {
         $command .= ' --force';
     }
     $input = new StringInput($command);
     $input->setInteractive(false);
     if (isset($this->notSupport[$input->getFirstArgument()]) === true) {
         throw new InvalidArgumentException('Command "' . $command . '" is not supported');
     }
     $this->artisan->handle($input, $this->getOutput());
 }
 public function run($command)
 {
     $kernel = $this->container->get('kernel');
     $app = new Application($kernel);
     $input = new StringInput($command);
     $input->setInteractive(false);
     $output = new StreamOutput(fopen('php://temp', 'w'));
     // Run the command
     $app->doRun($input, $output);
     rewind($output->getStream());
     $response = stream_get_contents($output->getStream());
     return $response;
 }
Exemple #10
0
 /**
  * Execute symfony cli command.
  *
  * @param string $commandString Command to execute
  * @return array
  */
 public function execute($commandString)
 {
     $input = new StringInput($commandString);
     $input->setInteractive(false);
     $output = new StringOutput();
     $formatter = $output->getFormatter();
     $formatter->setDecorated(true);
     $output->setFormatter(new HtmlConsoleOutputFormatter($formatter));
     //$application = new Application($this->getContainer()->get('kernel'));
     $application = $this->_getApplication($input);
     $kernel = $application->getKernel();
     chdir($kernel->getRootDir() . '/..');
     $application->setAutoExit(false);
     ob_start();
     $errorCode = $application->run($input, $output);
     $result = $output->getBuffer() || ob_get_contents();
     ob_end_clean();
     return array('input' => $commandString, 'output' => $output->getBuffer(), 'environment' => $kernel->getEnvironment(), 'errorcode' => $errorCode);
 }
 /**
  * Accepts $command input in format "your:symfony:command"
  *
  * @param string $command
  * @return int
  * @throws \Exception
  */
 protected static function runCommand($command)
 {
     $command = sprintf('%s', $command);
     $kernel = new \AppKernel('test', true);
     $kernel->boot();
     $application = new Application($kernel);
     $application->setAutoExit(false);
     $input = new StringInput($command);
     $input->setInteractive(false);
     return $application->run($input);
 }
Exemple #12
0
 public function ajaxAction()
 {
     $application = $this->container['application'];
     $input = new StringInput($this->command);
     $input->setInteractive(false);
     $output = new BufferedOutput();
     $formatter = $output->getFormatter();
     $formatter->setDecorated(true);
     $output->setFormatter(new HtmlOutputFormatter($formatter));
     $application->setAutoExit(false);
     // Some commands  dump things out instead of returning a value
     ob_start();
     $errorCode = $application->run($input, $output);
     if (!($result = $output->fetch())) {
         $result = ob_get_contents();
         // If empty, replace it by the catched output
     }
     ob_end_clean();
     $result = nl2br($result);
     $result = preg_replace('|<br />\\r.*<br />(\\r.*?)<br />|', '$1<br />', $result);
     return ['input' => $this->command, 'output' => $result, 'environment' => '', 'error_code' => $errorCode];
 }
 public function ajaxAction()
 {
     $application = $this->container['application'];
     $input = new StringInput($this->command);
     $input->setInteractive(false);
     $output = new BufferedOutput();
     $formatter = $output->getFormatter();
     $formatter->setDecorated(true);
     $output->setFormatter(new HtmlOutputFormatter($formatter));
     $application->setAutoExit(false);
     $endpoint = preg_replace('/(updater\\/|updater\\/index.php)$/', '', $this->request->getRequestUri());
     $fullEndpoint = sprintf('%s://%s%sindex.php/occ/', $this->request->getServerProtocol(), $this->request->getHost(), $endpoint !== '' ? $endpoint : '/');
     $application->setEndpoint($fullEndpoint);
     $application->setAuthToken($this->request->header('X_Updater_Auth'));
     // Some commands dump things out instead of returning a value
     ob_start();
     $errorCode = $application->run($input, $output);
     if (!($result = $output->fetch())) {
         $result = ob_get_contents();
         // If empty, replace it by the catched output
     }
     ob_end_clean();
     $result = nl2br($result);
     $result = preg_replace('|<br />\\r.*<br />(\\r.*?)<br />|', '$1<br />', $result);
     return ['input' => $this->command, 'output' => $result, 'environment' => '', 'error_code' => $errorCode];
 }