当前位置: 首页>>代码示例>>PHP>>正文


PHP Command::getDefinition方法代码示例

本文整理汇总了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());
 }
开发者ID:Maksold,项目名称:platform,代码行数:11,代码来源:OptionalListenersListener.php

示例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;
 }
开发者ID:drewmelck,项目名称:platformsh-cli,代码行数:37,代码来源:ArgvHelper.php

示例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);
             }
         }
     }
 }
开发者ID:mistymagich,项目名称:gush,代码行数:26,代码来源:HelpCommand.php

示例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');
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:13,代码来源:DelegateCommand.php

示例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());
 }
开发者ID:nrackleff,项目名称:capstone,代码行数:12,代码来源:CompletionHandler.php

示例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;
 }
开发者ID:smrtr,项目名称:mysql-version-control,代码行数:41,代码来源:ComposerParams.php

示例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);
 }
开发者ID:yvoronoy,项目名称:magento2-bash-completion,代码行数:11,代码来源:GeneratorSpec.php

示例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);
     }
 }
开发者ID:metro-q,项目名称:metro-bundle,代码行数:12,代码来源:CommandIntegrator.php

示例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;
 }
开发者ID:farukuzun,项目名称:core-1,代码行数:12,代码来源:commandtest.php

示例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);
 }
开发者ID:hatimeria,项目名称:PhpStormSupportBundle,代码行数:15,代码来源:GenerateCommandToolsConfigCommand.php

示例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;
 }
开发者ID:concrete5,项目名称:documentation_generator,代码行数:24,代码来源:GenerateCommand.php

示例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"));
 }
开发者ID:kingsj,项目名称:core,代码行数:23,代码来源:FormatProcessor.php

示例13: getDefinition

 public function getDefinition()
 {
     return $this->innerCommand->getDefinition();
 }
开发者ID:lolautruche,项目名称:ezsh,代码行数:4,代码来源:WrappedCommand.php

示例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);
 }
开发者ID:naldz,项目名称:cyberden,代码行数:32,代码来源:AbstractCommand.php

示例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();
 }
开发者ID:tonicforhealth,项目名称:behat-parallel-scenario,代码行数:8,代码来源:ParallelScenarioController.php


注:本文中的Symfony\Component\Console\Command\Command::getDefinition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。