本文整理汇总了PHP中Symfony\Component\Console\Command\Command::getDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::getDefinition方法的具体用法?PHP Command::getDefinition怎么用?PHP Command::getDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Command\Command
的用法示例。
在下文中一共展示了Command::getDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
示例2: 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;
}
示例3: updateCommandDefinition
private function updateCommandDefinition(Command $command, OutputInterface $output)
{
$eventDispatcher = $this->getApplication()->getDispatcher();
$input = new ArrayInput(['command' => $command->getName()]);
$event = new ConsoleCommandEvent($command, $input, $output);
$eventDispatcher->dispatch(GushEvents::DECORATE_DEFINITION, $event);
$command->getSynopsis(true);
$command->getSynopsis(false);
$command->mergeApplicationDefinition();
try {
$input->bind($command->getDefinition());
} catch (\Exception $e) {
$output->writeln('<error>Something went wrong: </error>' . $e->getMessage());
return;
}
$eventDispatcher->dispatch(GushEvents::INITIALIZE, $event);
// The options were set on the input but now we need to set them on the Command definition
if ($options = $input->getOptions()) {
foreach ($options as $name => $value) {
$option = $command->getDefinition()->getOption($name);
if ($option->acceptValue()) {
$option->setDefault($value);
}
}
}
}
示例4: configure
/**
* {@inheritDoc}
*/
protected function configure()
{
if ($this->isVersionCompatible()) {
$this->command = $this->createCommand();
$this->setHelp($this->command->getHelp());
$this->setDefinition($this->command->getDefinition());
$this->setDescription($this->command->getDescription());
}
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
}
示例5: getAllOptions
/**
* Get the combined options of the application and entered command
*
* @return InputOption[]
*/
protected function getAllOptions()
{
if (!$this->command) {
return $this->application->getDefinition()->getOptions();
}
return array_merge($this->command->getDefinition()->getOptions(), $this->application->getDefinition()->getOptions());
}
示例6: applyComposerParams
/**
* 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;
}
示例7: let
function let(CommandCollection $collection, Command $command1, Command $command2, InputDefinition $inputDefinition, InputDefinition $inputDefinition2, InputOption $inputOption, InputOption $inputOption2)
{
$inputDefinition->getOptions()->willReturn(['option1' => $inputOption, 'option2' => $inputOption2]);
$command1->getName()->willReturn('test:command');
$command1->getDefinition()->willReturn($inputDefinition);
$inputDefinition2->getOptions()->willReturn([]);
$command2->getName()->willReturn('other-command');
$command2->getDefinition()->willReturn($inputDefinition2);
$collection->getItems()->willReturn(['test:command' => $command1, 'other-command' => $command2]);
$this->beConstructedWith($collection);
}
示例8: integrate
public function integrate(Command $cmd)
{
$cmd->setName("metro:" . $cmd->getName());
$definition = $cmd->getDefinition();
$options = $definition->getOptions();
if (isset($options['short'])) {
// remove -s shortcut (already used by Symfony's --shell option)
$shortOption = $options['short'];
$options['short'] = new InputOption('short', null, InputOption::VALUE_NONE, $shortOption->getDescription());
$definition->setOptions($options);
}
}
示例9: getInput
protected function getInput(Command $command, array $arguments = [], array $options = [])
{
$input = new ArrayInput([]);
$input->bind($command->getDefinition());
foreach ($arguments as $key => $value) {
$input->setArgument($key, $value);
}
foreach ($options as $key => $value) {
$input->setOption($key, $value);
}
return $input;
}
示例10: getCommandParams
private function getCommandParams(Command $command)
{
$elements = array();
$definition = $command->getDefinition();
foreach ($definition->getArguments() as $argument) {
/** @var $option \Symfony\Component\Console\Input\Inputargument */
$elements[] = sprintf($argument->isRequired() ? '%s' : '[%s[="%s"]]', $argument->getName(), $argument->getDefault());
}
foreach ($definition->getOptions() as $option) {
/** @var $option \Symfony\Component\Console\Input\Inputoption */
$shortcut = $option->getshortcut() ? sprintf('-%s|', $option->getshortcut()) : '';
$elements[] = sprintf('[%s--%s[="%s"]]', $shortcut, $option->getname(), $option->getdefault());
}
return implode(' ', $elements);
}
示例11: getDefinition
/**
* Gets the InputDefinition attached to this Command.
*
* @return InputDefinition An InputDefinition instance
*
* @api
*/
public function getDefinition()
{
$definition = parent::getDefinition();
if (!$definition) {
$definition = new InputDefinition();
if ($this->default_generator) {
$generator = $this->getDefaultGenerator();
$generator->addDefinition($definition);
} else {
foreach ($this->generator_list as $generator) {
$generator->addDefinition($definition);
}
}
$this->setDefinition($definition);
}
return $definition;
}
示例12: configure
/**
* @see Behat\Behat\Console\Configuration\ProcessorInterface::configure()
*/
public function configure(Command $command)
{
$defaultFormatters = FormatManager::getDefaultFormatterClasses();
$defaultLanguage = null;
if (($locale = getenv('LANG')) && preg_match('/^([a-z]{2})/', $locale, $matches)) {
$defaultLanguage = $matches[1];
}
$command->addOption('--format', '-f', InputOption::VALUE_REQUIRED, "How to format features. <comment>pretty</comment> is default.\n" . "Default formatters are:\n" . implode("\n", array_map(function ($name) use($defaultFormatters) {
$class = $defaultFormatters[$name];
return "- <comment>{$name}</comment>: " . $class::getDescription();
}, array_keys($defaultFormatters))) . "\n" . "Can use multiple formats at once (splitted with \"<comment>,</comment>\")")->addOption('--out', null, InputOption::VALUE_REQUIRED, "Write formatter output to a file/directory\n" . "instead of STDOUT <comment>(output_path)</comment>.")->addOption('--lang', null, InputOption::VALUE_REQUIRED, 'Print formatter output in particular language.', $defaultLanguage);
$definition = $command->getDefinition();
$definition->addOption(new InputSwitch('--[no-]ansi', "Whether or not to use ANSI color in the output.\n" . "Behat decides based on your platform and the output\n" . "destination if not specified."));
$definition->addOption(new InputSwitch('--[no-]time', "Whether or not to show timer in output."));
$definition->addOption(new InputSwitch('--[no-]paths', "Whether or not to print sources paths."));
$definition->addOption(new InputSwitch('--[no-]snippets', "Whether or not to print snippets for undefined steps."));
$definition->addOption(new InputSwitch('--[no-]snippets-paths', "Whether or not to print details about undefined steps\n" . "in their snippets."));
$definition->addOption(new InputSwitch('--[no-]multiline', "Whether or not to print multiline arguments for steps."));
$definition->addOption(new InputSwitch('--[no-]expand', "Whether or not to expand scenario outline examples\n" . "tables.\n"));
}
示例13: getDefinition
public function getDefinition()
{
return $this->innerCommand->getDefinition();
}
示例14: runCommand
/**
* Run a Symfony command.
*
* @param Command $command The command to run.
* @param array $parameters An array of parameters to give to the command.
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return int The command return code.
*/
protected function runCommand(Command $command, array $parameters, InputInterface $input, OutputInterface $output)
{
// add the command's name to the parameters
array_unshift($parameters, $this->getName());
// merge the default parameters
$extraParameters = ['--verbose' => $input->getOption('verbose')];
if ($command->getDefinition()->hasOption('schema-dir')) {
$extraParameters['--schema-dir'] = $this->cacheDir;
}
if ($command->getDefinition()->hasOption('config-dir')) {
$extraParameters['--config-dir'] = $this->cacheDir;
}
$parameters = array_merge($extraParameters, $parameters);
if ($input->hasOption('platform')) {
if ($platform = $input->getOption('platform') ?: $this->getPlatform()) {
$parameters['--platform'] = $platform;
}
}
$command->setApplication($this->getApplication());
// and run the sub-command
return $command->run(new ArrayInput($parameters), $output);
}
示例15: configure
/**
* {@inheritdoc}
*/
public function configure(SymfonyCommand $command)
{
$command->addOption(self::OPTION_PARALLEL_PROCESS, null, InputOption::VALUE_OPTIONAL, 'Max parallel processes amount', 1);
$this->inputDefinition = $command->getDefinition();
}