run() 공개 메소드

The code to execute is either defined directly with the setCode() method or by overriding the execute() method in a sub-class.
또한 보기: setCode()
또한 보기: execute()
public run ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer
$input Symfony\Component\Console\Input\InputInterface An InputInterface instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance
리턴 integer The command exit code
 /**
  * Perform the actual check and return a ResultInterface
  *
  * @return ResultInterface
  * @throws \Exception
  */
 public function check()
 {
     $exitCode = $this->command->run($this->input, $this->output);
     $data = [];
     if ($this->output instanceof PropertyOutput) {
         $data = $this->output->getMessage();
         if (!is_array($data)) {
             $data = explode(PHP_EOL, trim($data));
         }
     }
     if ($exitCode < 1) {
         return new Success(get_class($this->command), $data);
     }
     return new Failure(get_class($this->command), $data);
 }
예제 #2
0
 public function run(InputInterface $input, OutputInterface $output)
 {
     // Store the input and output for easier usage
     $this->input = $input;
     $this->output = $output;
     parent::run($input, $output);
 }
예제 #3
0
 /**
  * Execute this console command
  *
  * @param  InputInterface  $input  Command line input interface
  * @param  OutputInterface $output Command line output interface
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $dropTables = $input->getOption('drop-tables');
     if (!$this->hasTablesOrViews() || $dropTables) {
         if ($dropTables && $this->appEnv === 'production') {
             $output->writeln('Cannot drop tables when app environment is production.');
             return;
         }
         // Console message heading padded by a newline
         $output->write(['', '  -- APP INSTALL --', ''], true);
         $output->write(['  Dropping tables', ''], true);
         $this->dropViews();
         $this->dropTables();
         try {
             $installScript = $this->getInstallScript();
         } catch (RuntimeException $e) {
             $output->writeln($e->getMessage());
             return;
         }
         $this->install($installScript, $output);
     }
     // Run all migrations
     $output->writeln('  Executing new migrations');
     $this->runMigrationsCommand->run(new ArrayInput(['migrations:run']), $output);
     $output->write(['  Done!', ''], true);
 }
예제 #4
0
 /**
  * Run given command and return its output.
  *
  * @param Command $command
  * @param array $input
  * @return string
  */
 protected function runCommand(Command $command, array $input = [])
 {
     $stream = fopen("php://memory", "r+");
     $input = new ArrayInput($input);
     $command->run($input, new StreamOutput($stream));
     rewind($stream);
     return stream_get_contents($stream);
 }
 private function executeCommand(Command $command, Input $input)
 {
     $command->setApplication($this->application);
     $input->setInteractive(false);
     if ($command instanceof ContainerAwareCommand) {
         $command->setContainer($this->client->getContainer());
     }
     $command->run($input, new NullOutput());
 }
 public function run(InputInterface $input, OutputInterface $output)
 {
     try {
         return parent::run($input, $output);
     } catch (\Exception $e) {
         if ($input->getOption('alert')) {
             mtrace($e, "Exception while running command " . $this->getName(), 'alert');
         }
         throw $e;
     }
 }
예제 #7
0
 /**
  * Override run to let Exceptions function as exit codes.
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     try {
         return parent::run($input, $output);
     } catch (Exception $e) {
         $output->writeln("<error>" . $e->getMessage() . "</error>");
         return $e->getCode() > 0 ? $e->getCode() : 1;
     }
 }
예제 #8
0
 protected static function executeCommand(Command $command, $siteDir)
 {
     if (!is_dir($siteDir)) {
         throw new \RuntimeException('The meinhof-site-dir (' . $siteDir . ') specified in composer.json was not found in ' . getcwd());
     }
     $helpers = new HelperSet(array(new FormatterHelper(), new DialogHelper()));
     $command->setHelperSet($helpers);
     $input = new ArrayInput(array('dir' => $siteDir));
     $output = new ConsoleOutput();
     $command->run($input, $output);
 }
예제 #9
0
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->depedencies = $this->getApplication()->getKernel()->getContainer()->get('mardraze_core.depedencies');
     $context = $this->depedencies->get('router')->getContext();
     $mainHost = $this->depedencies->getParameter('mardraze_http_host');
     $host = preg_replace('/http(s)?:\\/\\//', '', $mainHost);
     $scheme = strpos($mainHost, 'https:') === false ? 'http' : 'https';
     $context->setHost($host);
     $context->setScheme($scheme);
     $this->input = $input;
     $this->output = $output;
     return parent::run($input, $output);
 }
예제 #10
0
파일: BaseCommand.php 프로젝트: liip/rmt
 /**
  * {@inheritdoc}
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // Store the input and output for easier usage
     $this->input = $input;
     if (!$output instanceof Output) {
         throw new \InvalidArgumentException('Not the expected output type');
     }
     $this->output = $output;
     $dialogHelper = class_exists('Symfony\\Component\\Console\\Helper\\QuestionHelper') ? $this->getHelperSet()->get('question') : $this->getHelperSet()->get('dialog');
     $this->output->setDialogHelper($dialogHelper);
     $this->output->setFormatterHelper($this->getHelperSet()->get('formatter'));
     Context::getInstance()->setService('input', $this->input);
     Context::getInstance()->setService('output', $this->output);
     parent::run($input, $output);
 }
 /**
  * Runs the command.
  *
  * Before the decorated command is run, a lock is requested.
  * When failed to acquire the lock, the command exits.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return int The command exit code
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->mergeApplicationDefinition();
     $input->bind($this->getDefinition());
     $lock = $this->getLockHandler($input);
     if (!$lock->lock()) {
         $this->writeLockedMessage($input, $output);
         return 1;
     }
     try {
         return $this->decoratedCommand->run($input, $output);
     } finally {
         $lock->release();
     }
 }
예제 #12
0
    public function run(InputInterface $input, OutputInterface $output)
    {
        try {
            return parent::run($input, $output);
        } catch (RuntimeException $e) {
            if ($e->getMessage() === 'invalid token') {
                throw new AuthException(<<<TEXT
Your authentication token is invalid or has not been set yet.
Execute 'trello config generate' and follow the instructions.
TEXT
);
            } else {
                throw $e;
            }
        }
    }
 /**
  * @see Symfony\Component\Console\Command\Command::run()
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // Force the creation of the synopsis before the merge with the app definition
     $this->getSynopsis();
     // Merge our options
     $this->addOption('run-once', null, InputOption::VALUE_NONE, 'Run the command just once, do not go into an endless loop');
     $this->addOption('detect-leaks', null, InputOption::VALUE_NONE, 'Output information about memory usage');
     // Add the signal handler
     if (function_exists('pcntl_signal')) {
         // Enable ticks for fast signal processing
         declare (ticks=1);
         pcntl_signal(SIGTERM, array($this, 'handleSignal'));
         pcntl_signal(SIGINT, array($this, 'handleSignal'));
     }
     // And now run the command
     return parent::run($input, $output);
 }
예제 #14
0
파일: Shell.php 프로젝트: kodazzi/framework
 public function execute(Command $command, array $input, array $options = array())
 {
     // set the command name automatically if the application requires
     // this argument and no command name was passed
     if (!isset($input['command']) && null !== ($application = $this->command->getApplication()) && $application->getDefinition()->hasArgument('command')) {
         $input = array_merge(array('command' => $this->command->getName()), $input);
     }
     $this->input = new ArrayInput($input);
     if (isset($options['interactive'])) {
         $this->input->setInteractive($options['interactive']);
     }
     $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']);
     }
     return $this->statusCode = $command->run($this->input, $this->output);
 }
예제 #15
0
파일: base.php 프로젝트: ZverAleksey/core
 public function run(InputInterface $input, OutputInterface $output)
 {
     // check if the php pcntl_signal functions are accessible
     $this->php_pcntl_signal = function_exists('pcntl_signal');
     if ($this->php_pcntl_signal) {
         // Collect interrupts and notify the running command
         pcntl_signal(SIGTERM, [$this, 'cancelOperation']);
         pcntl_signal(SIGINT, [$this, 'cancelOperation']);
     }
     return parent::run($input, $output);
 }
예제 #16
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->getHelperSet()->setCommand($this);
     return parent::run($input, $output);
 }
예제 #17
0
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->getApplication()->getDispatcher()->dispatch(GushEvents::DECORATE_DEFINITION, new ConsoleCommandEvent($this, $input, $output));
     return parent::run($input, $output);
 }
 /**
  * @param Command         $command
  * @param array           $arguments
  * @param OutputInterface $output
  *
  * @return integer Exit code
  */
 protected function executeCommand(Command $command, array $arguments, OutputInterface $output)
 {
     $output = clone $output;
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $output->setVerbosity($output->getVerbosity());
     } else {
         $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
     }
     return $command->run(new ArrayInput($arguments), $output);
 }
예제 #19
0
 /**
  * {@inheritdoc}
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     $helperSet = $command->getHelperSet();
     foreach ($helperSet as $helper) {
         if ($helper instanceof OutputAwareInterface) {
             $helper->setOutput($output);
         }
         if ($helper instanceof InputAwareInterface) {
             $helper->setInput($input);
         }
     }
     $event = new ConsoleCommandEvent($command, $input, $output);
     $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     try {
         $exitCode = $command->run($input, $output);
     } catch (\Exception $e) {
         $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
         $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
         $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
         $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
         if ($e instanceof UserException) {
             $this->getHelperSet()->get('gush_style')->error($e->getMessages());
             if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                 throw $e;
             }
             return $event->getExitCode();
         } else {
             throw $event->getException();
         }
     }
     $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
     $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
     return $event->getExitCode();
 }
예제 #20
0
 public function run(InputInterface $input, OutputInterface $output)
 {
     return $this->innerCommand->run($input, $output);
 }
예제 #21
0
 /**
  * {@inheritdoc}
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->eventEmitter->emit('peridot.execute', $input, $output);
     $this->eventEmitter->emit('peridot.reporters', $input, $this->factory);
     return parent::run($input, $output);
 }
예제 #22
0
 /**
  * Run the console command.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface  $input
  * @param  \Symfony\Component\Console\Output\OutputInterface  $output
  * @return integer
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     return parent::run($input, $output);
 }
예제 #23
0
 /**
  * @expectedException        \LogicException
  * @expectedExceptionMessage You must override the execute() method in the concrete command class.
  */
 public function testExecuteMethodNeedsToBeOverriden()
 {
     $command = new Command('foo');
     $command->run(new StringInput(''), new NullOutput());
 }
예제 #24
0
 /**
  * Run the build command
  *
  * @param OutputInterface $output
  */
 protected function build(OutputInterface $output)
 {
     $this->command->run($this->input, $output);
     $this->lastBuild = new DateTime();
 }
예제 #25
0
 /**
  * Runs the current command.
  *
  * If an event dispatcher has been attached to the application,
  * events are also dispatched during the life-cycle of the command.
  *
  * @param Command         $command A Command instance
  * @param InputInterface  $input   An Input instance
  * @param OutputInterface $output  An Output instance
  *
  * @return int 0 if everything went fine, or an error code
  *
  * @throws \Exception when the command being run threw an exception
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     foreach ($command->getHelperSet() as $helper) {
         if ($helper instanceof InputAwareInterface) {
             $helper->setInput($input);
         }
     }
     if (null === $this->dispatcher) {
         return $command->run($input, $output);
     }
     // bind before the console.command event, so the listeners have access to input options/arguments
     try {
         $command->mergeApplicationDefinition();
         $input->bind($command->getDefinition());
     } catch (ExceptionInterface $e) {
         // ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition
     }
     $event = new ConsoleCommandEvent($command, $input, $output);
     $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     if ($event->commandShouldRun()) {
         try {
             $exitCode = $command->run($input, $output);
         } catch (\Exception $e) {
             $event = new ConsoleExceptionEvent($command, $input, $output, $e, $e->getCode());
             $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
             $e = $event->getException();
             $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
             $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
             throw $e;
         }
     } else {
         $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
     }
     $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
     $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
     return $event->getExitCode();
 }
예제 #26
0
파일: Command.php 프로젝트: abava/console
 /**
  * Making method final to restrict overwrite
  *
  * {@inheritdoc}
  */
 public final function run(InputInterface $input, OutputInterface $output) : int
 {
     return parent::run($input, $output);
 }
 public function testRun()
 {
     $command = new \TestCommand();
     $tester = new CommandTester($command);
     try {
         $tester->execute(array('--bar' => true));
         $this->fail('->run() throws a \\InvalidArgumentException when the input does not validate the current InputDefinition');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->run() throws a \\InvalidArgumentException when the input does not validate the current InputDefinition');
         $this->assertEquals('The "--bar" option does not exist.', $e->getMessage(), '->run() throws a \\InvalidArgumentException when the input does not validate the current InputDefinition');
     }
     $tester->execute(array(), array('interactive' => true));
     $this->assertEquals('interact called' . PHP_EOL . 'execute called' . PHP_EOL, $tester->getDisplay(), '->run() calls the interact() method if the input is interactive');
     $tester->execute(array(), array('interactive' => false));
     $this->assertEquals('execute called' . PHP_EOL, $tester->getDisplay(), '->run() does not call the interact() method if the input is not interactive');
     $command = new Command('foo');
     try {
         $command->run(new StringInput(''), new NullOutput());
         $this->fail('->run() throws a \\LogicException if the execute() method has not been overridden and no code has been provided');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\LogicException', $e, '->run() throws a \\LogicException if the execute() method has not been overridden and no code has been provided');
         $this->assertEquals('You must override the execute() method in the concrete command class.', $e->getMessage(), '->run() throws a \\LogicException if the execute() method has not been overridden and no code has been provided');
     }
 }
예제 #28
0
파일: Command.php 프로젝트: vvval/spiral
 /**
  * {@inheritdoc}
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     //We can refill internal options as we don't need them at this stage
     $this->options = $this->input->getOptions();
     $this->arguments = $this->input->getArguments();
     return parent::run($input, $output);
 }
예제 #29
0
 /**
  * Runs the current command.
  *
  * If an event dispatcher has been attached to the application,
  * events are also dispatched during the life-cycle of the command.
  *
  * @param Command         $command A Command instance
  * @param InputInterface  $input   An Input instance
  * @param OutputInterface $output  An Output instance
  *
  * @return int 0 if everything went fine, or an error code
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     foreach ($command->getHelperSet() as $helper) {
         if ($helper instanceof InputAwareInterface) {
             $helper->setInput($input);
         }
     }
     if (null === $this->dispatcher) {
         return $command->run($input, $output);
     }
     $event = new ConsoleCommandEvent($command, $input, $output);
     $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     try {
         $exitCode = $command->run($input, $output);
     } catch (\Exception $e) {
         $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
         $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
         $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
         $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
         throw $event->getException();
     }
     $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
     $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
     return $event->getExitCode();
 }
예제 #30
0
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->getIO()->write($this->getApplication()->getLongVersion());
     $this->getIO()->write('');
     return parent::run($input, $output);
 }