本文整理汇总了PHP中Symfony\Component\Console\Command\Command类的典型用法代码示例。如果您正苦于以下问题:PHP Command类的具体用法?PHP Command怎么用?PHP Command使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: configure
/**
* {@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.');
}
示例2: execute
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;
}
示例3: getDependencies
/**
* @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()]);
}
示例4: assert
/**
* @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));
}
示例5: add
/**
* @param Command $command
* @return Command
*/
public function add(Command $command)
{
if ($command instanceof AbstractPimpleCommand) {
$command->setContainer($this->container);
}
return parent::add($command);
}
示例6: add
/**
* 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);
}
示例7: simulateHelperSet
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);
}
示例8: add
/**
* 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);
}
示例9: addOptionsToCommand
/**
* @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());
}
示例10: stripOptions
/**
* 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;
}
示例11: add
/**
* @param Command $command
* @return Command
*/
public function add(Command $command)
{
if ($command instanceof ContainerAwareInterface) {
$command->setContainer($this->container);
}
return parent::add($command);
}
示例12: doRunCommand
/**
* @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);
}
示例13: add
/**
* 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);
}
示例14: doRunCommand
/**
* @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: containerize_command
/**
* @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;
}