Exemple #1
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('xml')) {
         $output->write($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
     } else {
         $output->write($this->application->asText($input->getArgument('namespace')));
     }
 }
Exemple #2
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (null === $this->command) {
         $this->command = $this->application->getCommand($input->getArgument('command_name'));
     }
     if ($input->getOption('xml')) {
         $output->write($this->command->asXml(), Output::OUTPUT_RAW);
     } else {
         $output->write($this->command->asText());
     }
 }
Exemple #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $output->write('called');
 }
Exemple #4
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $output->write('interact called');
 }
Exemple #5
0
 /**
  * Renders a catched exception.
  *
  * @param Exception       $e      An exception instance
  * @param OutputInterface $output An OutputInterface instance
  */
 public function renderException($e, $output)
 {
     $strlen = function ($string) {
         return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
     };
     $title = sprintf('  [%s]  ', get_class($e));
     $len = $strlen($title);
     $lines = array();
     foreach (explode("\n", $e->getMessage()) as $line) {
         $lines[] = sprintf('  %s  ', $line);
         $len = max($strlen($line) + 4, $len);
     }
     $messages = array(str_repeat(' ', $len), $title . str_repeat(' ', $len - $strlen($title)));
     foreach ($lines as $line) {
         $messages[] = $line . str_repeat(' ', $len - $strlen($line));
     }
     $messages[] = str_repeat(' ', $len);
     $output->write("\n");
     foreach ($messages as $message) {
         $output->write("<error>{$message}</error>");
     }
     $output->write("\n");
     if (null !== $this->runningCommand) {
         $output->write(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
         $output->write("\n");
     }
     if (Output::VERBOSITY_VERBOSE === $output->getVerbosity()) {
         $output->write('</comment>Exception trace:</comment>');
         // exception related properties
         $trace = $e->getTrace();
         array_unshift($trace, array('function' => '', 'file' => $e->getFile() != null ? $e->getFile() : 'n/a', 'line' => $e->getLine() != null ? $e->getLine() : 'n/a', 'args' => array()));
         for ($i = 0, $count = count($trace); $i < $count; $i++) {
             $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
             $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
             $function = $trace[$i]['function'];
             $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
             $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
             $output->write(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line));
         }
         $output->write("\n");
     }
 }
Exemple #6
0
 /**
  * Asks for a value and validates the response.
  *
  * @param OutputInterface $output
  * @param string|array    $question
  * @param Closure         $validator
  * @param integer         $attempts Max number of times to ask before giving up (false by default, which means infinite)
  *
  * @return mixed
  */
 public static function askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts = false)
 {
     // @codeCoverageIgnoreStart
     $error = null;
     while (false === $attempts || $attempts--) {
         if (null !== $error) {
             $output->write($this->formatter->formatBlock($error->getMessage(), 'error'));
         }
         $value = static::ask($output, $question, null);
         try {
             return $validator($value);
         } catch (\Exception $error) {
         }
     }
     throw $error;
     // @codeCoverageIgnoreEnd
 }