示例#1
2
 /**
  * @param Command $command
  * @return array
  */
 public function getDependencies(Command $command)
 {
     if (!array_key_exists($command->getName(), $this->commands)) {
         return [];
     }
     return array_keys($this->commands[$command->getName()]);
 }
示例#2
2
 /**
  * {@inheritdoc}
  */
 public function configure(Command $command)
 {
     $locatorsExamples = implode(PHP_EOL, array_map(function ($locator) {
         return '- ' . $locator;
     }, $this->specificationFinder->getExampleLocators()));
     $command->addArgument('paths', InputArgument::OPTIONAL, 'Optional path(s) to execute. Could be:' . PHP_EOL . $locatorsExamples)->addOption('--dry-run', null, InputOption::VALUE_NONE, 'Invokes formatters without executing the tests and hooks.');
 }
示例#3
2
 /**
  * @param $condition
  * @param $message
  */
 private function assert($condition, $message)
 {
     if ($condition) {
         return;
     }
     throw new RuntimeException(sprintf('Command %s is not available because %s.', $this->command->getName(), $message));
 }
示例#4
1
 /**
  * Strip a command's options from an argv array.
  *
  * @param string[] $args
  * @param Command  $command
  *
  * @return string[]
  */
 protected function stripOptions(array $args, Command $command)
 {
     $definition = $command->getDefinition();
     foreach ($args as $key => $arg) {
         // Only consider options.
         if ($arg[0] !== '-') {
             continue;
         }
         // Look up the option. If it exists in the command definition,
         // remove it from the $args array.
         $argAsOption = preg_replace('/^\\-+([^=]+).*/', '$1', $arg);
         if ($definition->hasOption($argAsOption)) {
             $option = $definition->getOption($argAsOption);
         } else {
             try {
                 $option = $definition->getOptionForShortcut($argAsOption);
             } catch (\InvalidArgumentException $e) {
                 continue;
             }
         }
         // Unset the option.
         unset($args[$key]);
         // Unset the option's value too.
         if ($option->acceptValue() && isset($args[$key + 1]) && !strpos($arg, '=') && $args[$key + 1][0] !== '-') {
             unset($args[$key + 1]);
         }
     }
     return $args;
 }
示例#5
1
 /**
  * @param Command $command
  * @return Command
  */
 public function add(Command $command)
 {
     if ($command instanceof ContainerAwareInterface) {
         $command->setContainer($this->container);
     }
     return parent::add($command);
 }
示例#6
1
 /**
  * @override
  * @inheritDoc
  */
 protected function doRunCommand(SymfonyCommand $command, InputInterface $input, OutputInterface $output)
 {
     if ($command instanceof CommandInterface && $command->isAsync() === true) {
         $this->async = true;
     }
     return parent::doRunCommand($command, $input, $output);
 }
 /**
  * @param Command $command
  * @param InputInterface $input
  */
 protected function addOptionsToCommand(Command $command, InputInterface $input)
 {
     $inputDefinition = $command->getApplication()->getDefinition();
     $inputDefinition->addOption(new InputOption(self::DISABLE_OPTIONAL_LISTENERS, null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, sprintf('Disable optional listeners, "%s" to disable all listeners, ' . 'command "%s" shows all listeners', self::ALL_OPTIONAL_LISTENERS_VALUE, OptionalListenersCommand::NAME)));
     $command->mergeApplicationDefinition();
     $input->bind($command->getDefinition());
 }
示例#8
1
 public function simulateHelperSet(Command $command)
 {
     $this->dialog = $this->getMock("Symfony\\Component\\Console\\Helper\\DialogHelper");
     $helpers = array('dialog' => $this->dialog);
     $helperSet = new HelperSet($helpers);
     $command->setHelperSet($helperSet);
 }
示例#9
1
 /**
  * Add a command to the console.
  *
  * @param  \Symfony\Component\Console\Command\Command  $command
  * @return \Symfony\Component\Console\Command\Command
  */
 public function add(SymfonyCommand $command)
 {
     if ($command instanceof Command) {
         $command->setLaravel($this->laravel);
     }
     return $this->addToParent($command);
 }
 /**
  * Add a command to the console.
  *
  * @param  BaseCommand $command
  * @return BaseCommand
  */
 public function add(BaseCommand $command)
 {
     if ($command instanceof Command) {
         $command->setPagekit($this->pagekit);
     }
     return parent::add($command);
 }
 /**
  * @param  Command $command
  * @return Command
  */
 public function add(Command $command)
 {
     if ($command instanceof AbstractPimpleCommand) {
         $command->setContainer($this->container);
     }
     return parent::add($command);
 }
 public function __construct(Command $singleCommand)
 {
     global $argv;
     $this->singleCommand = $singleCommand;
     // Use the command's name as the whole app's name
     $this->setName($singleCommand->getName());
     // Then set the command's name to be the name of the script file
     //  executed (as executed, regardless of symlinks, etc) - i.e.
     //  whatever's set as $argv[0] - because this name ends up displayed in
     //  the "Usage" line of the `--help` output. Though we use the executed
     //  script's base name (i.e. none of the directories leading to it)
     //  because including any parts of the directory path results in a
     //  `--help` output that's very different to all native/standard
     //  commands.
     // This will result in the "Usage" section displaying as:
     //     my-command.php [options] [--] <arguments>
     //  instead of showing the name of the command in place of
     //  'my-command.php', which is especially useful for single-command
     //  apps, as the command name is never even referenced anywhere else!
     $commandName = isset($argv[0]) ? basename($argv[0]) : 'command.php';
     $singleCommand->setName($commandName);
     parent::__construct();
     $this->add($singleCommand);
     $this->setDefaultCommand($singleCommand->getName());
     // If the command class has an 'APP_VERSION' constant defined, we use
     //  that as the entire app's version, as this seems like a much more
     //  sensible place to indicate the version than in the Application
     //  constructor which is tucked away in a non-obvious place!
     $commandClass = get_class($singleCommand);
     if (defined($commandClass . '::APP_VERSION')) {
         $this->setVersion(constant($commandClass . '::APP_VERSION'));
     }
 }
示例#13
0
 /**
  * @param \Symfony\Component\Console\Command\Command $command
  * @return \Symfony\Component\Console\Command\Command
  */
 public function add(SymfonyCommand $command)
 {
     if ($command instanceof Command) {
         $command->setNotadd($this->notadd);
     }
     return $this->addToParent($command);
 }
示例#14
0
 /**
  * @param Command $command
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  * @throws \Exception
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     if ($command instanceof FactoryAwareInterface) {
         $command->setFactory($this->factory);
     }
     return parent::doRunCommand($command, $input, $output);
 }
示例#15
0
 /**
  * @param  Command $command
  * @return Command
  */
 public function add(Command $command)
 {
     if ($command instanceof ContainerAwareCommand) {
         $command->setContainer($this->getContainer());
     }
     return parent::add($command);
 }
 /**
  * Applies parameters that are defined in the extra section of composer.json.
  *
  * If the Input object already has a value for the argument or parameter then the value in composer is ignored.
  *
  * @param Command $command
  * @param InputInterface $input
  *
  * @return $this
  * @throws MysqlVersionControlException
  */
 public function applyComposerParams(Command $command, InputInterface $input)
 {
     $params = $this->getComposerParams($input->getArgument("env"));
     $definition = $command->getDefinition();
     foreach ($this->filterComposerParams($params, $definition) as $param => $value) {
         if (0 === strpos($param, "--")) {
             // option
             $option = substr($param, 2);
             $Option = $definition->getOption($option);
             if (!$Option->acceptValue() && false === $input->getOption($option)) {
                 $input->setOption($option, null);
             } elseif ($Option->acceptValue() && $Option->getDefault() === $input->getOption($option)) {
                 if ($Option->isArray()) {
                     $input->setOption($option, is_array($value) ? $value : [$value]);
                 } elseif (is_array($value)) {
                     throw new MysqlVersionControlException("The '{$option}' option does not accept arrays. Check your composer.json");
                 } else {
                     $input->setOption($option, $value);
                 }
             }
         } else {
             // argument
             $argument = $definition->getArgument($param);
             if ($argument->getDefault() === $input->getArgument($param)) {
                 $input->setArgument($param, $value);
             }
         }
     }
     return $this;
 }
示例#17
0
 /**
  * Add command
  *
  * @param SymfonyCommand $command
  * @return SymfonyCommand
  */
 public function add(SymfonyCommand $command)
 {
     if ($command instanceof Command) {
         $command->setConfig($this->config)->setLog($this->log);
     }
     return parent::add($command);
 }
示例#18
0
 private function execute(array $fileStructure, array $options = []) : CommandTester
 {
     $fs = vfsStream::create($fileStructure, vfsStream::setup(getcwd()));
     $commandTester = new CommandTester($this->command);
     $commandTester->execute(array_merge(['command' => $this->command->getName(), 'path' => $fs->url()], $options));
     return $commandTester;
 }
示例#19
0
/**
 * @param Container $container
 * @param SymfonyCommand $command
 * @return Command|SymfonyCommand
 */
function containerize_command(Container $container, SymfonyCommand $command)
{
    if ($command instanceof Command) {
        $command->setContainer($container);
    }
    return $command;
}
示例#20
0
 public static function configureTargetConnectionOptions(BaseCommand $command)
 {
     $command->addOption('target-host', null, InputArgument::OPTIONAL, 'Neo4j source server hostname');
     $command->addOption('target-port', null, InputArgument::OPTIONAL, 'Neo4j source server port');
     $command->addOption('target-user', null, InputArgument::OPTIONAL, 'Neo4j source server username');
     $command->addOption('target-password', null, InputArgument::OPTIONAL, 'Neo4j source server password');
 }
示例#21
0
 public function testConsoleEvent()
 {
     $dispatcher = new EventDispatcher();
     $listener = new DebugHandlersListener(null);
     $app = $this->getMock('Symfony\\Component\\Console\\Application');
     $app->expects($this->once())->method('getHelperSet')->will($this->returnValue(new HelperSet()));
     $command = new Command(__FUNCTION__);
     $command->setApplication($app);
     $event = new ConsoleEvent($command, new ArgvInput(), new ConsoleOutput());
     $dispatcher->addSubscriber($listener);
     $xListeners = array(KernelEvents::REQUEST => array(array($listener, 'configure')), ConsoleEvents::COMMAND => array(array($listener, 'configure')));
     $this->assertSame($xListeners, $dispatcher->getListeners());
     $exception = null;
     $eHandler = new ErrorHandler();
     set_error_handler(array($eHandler, 'handleError'));
     set_exception_handler(array($eHandler, 'handleException'));
     try {
         $dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     } catch (\Exception $exception) {
     }
     restore_exception_handler();
     restore_error_handler();
     if (null !== $exception) {
         throw $exception;
     }
     $xHandler = $eHandler->setExceptionHandler('var_dump');
     $this->assertInstanceOf('Closure', $xHandler);
     $app->expects($this->once())->method('renderException');
     $xHandler(new \Exception());
 }
 /**
  * {@inheritdoc}
  */
 protected function getCommandName(InputInterface $input)
 {
     $stream = $this->getStdinStream();
     $hasStdin = $stream->getSize() > 0;
     $this->pluginCommand->setStream($stream);
     return $hasStdin ? $this->pluginCommand->getName() : $this->generateCommand->getName();
 }
示例#23
0
 /**
  * {@inheritdoc}
  */
 public function add(SymfonyCommand $command)
 {
     if ($command instanceof AutarkyCommand) {
         $command->setAutarkyApplication($this->app);
     }
     return parent::add($command);
 }
示例#24
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (is_null($this->command)) {
         $this->command = $this->getApplication()->get($input->getArgument('command_name'));
     }
     $output->writeln($this->command->asText());
 }
示例#25
0
 /**
  * @inheritdoc
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     if ($command->getName() != 'version') {
         $output->writeln($this->getLongVersion());
     }
     return parent::doRunCommand($command, $input, $output);
 }
 /**
  * Pass the container to Container Aware Command classes
  *
  * @param Command $command
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return mixed
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     if ($command instanceof ContainerAwareInterface) {
         $command->setContainer($this->getContainer());
     }
     return parent::doRunCommand($command, $input, $output);
 }
示例#27
0
 /**
  * {@inheritdoc}
  */
 public function add(Command $command)
 {
     if ($command instanceof \Consoler\Command) {
         $command->setContainer($this->container);
     }
     return parent::add($command);
 }
示例#28
0
 /**
  * @dataProvider inputInteractiveCommandToOutputFilesProvider
  */
 public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath)
 {
     $code = (require $inputCommandFilepath);
     $this->command->setCode($code);
     $this->tester->execute(array(), array('interactive' => true, 'decorated' => false));
     $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
 }
示例#29
0
 /**
  * @param $command
  *
  * @return \Symfony\Component\Console\Command\Command|void
  */
 public function add(SymfonyCommand $command)
 {
     if ($command instanceof Command) {
         $command->setCygnite($this->cygnite);
     }
     parent::add($command);
 }
 public function execute()
 {
     $go = $this->getGo();
     if (!$go) {
         return $this->vars;
     }
     list($loopVarName, $loopCount) = $this->getLoopCount();
     if ($loopCount) {
         foreach ($loopCount as $loopVarValue) {
             $commandString = is_array($this->value) ? $this->value['value'] : $this->value;
             $commandArgs = explode(' ', $commandString);
             $replacedArrayArgs = array_map(function ($commandArg) use($loopVarName, $loopVarValue) {
                 return $this->replaceVarsInString($commandArg, [$loopVarName => $loopVarValue]);
             }, $commandArgs);
             $subCommand = $this->command->getApplication()->find(reset($commandArgs));
             $subCommand->run(new StringInput(implode(' ', $replacedArrayArgs)), $this->output);
         }
     } else {
         $commandString = is_array($this->value) ? $this->value['value'] : $this->value;
         $commandArgs = explode(' ', $commandString);
         $replacedArrayArgs = array_map([$this, 'replaceVarsInString'], $commandArgs);
         $subCommand = $this->command->getApplication()->find(reset($commandArgs));
         $subCommand->run(new StringInput(implode(' ', $replacedArrayArgs)), $this->output);
     }
     return $this->vars;
 }