本文整理汇总了PHP中Symfony\Component\Console\Input\InputDefinition::addOption方法的典型用法代码示例。如果您正苦于以下问题:PHP InputDefinition::addOption方法的具体用法?PHP InputDefinition::addOption怎么用?PHP InputDefinition::addOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Input\InputDefinition
的用法示例。
在下文中一共展示了InputDefinition::addOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: providerMake
/**
* @return array
*/
public function providerMake()
{
$inputDefinition = new InputDefinition();
$inputDefinition->addOption(new InputOption('option_optional_default', null, InputOption::VALUE_OPTIONAL, '', 'default'));
$inputDefinition->addOption(new InputOption('option_array_default_array', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY));
$inputDefinition->addOption(new InputOption('option_none', null, InputOption::VALUE_NONE));
$inputDefinition->addOption(new InputOption('out', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY));
return ['option_optional_default_default' => [$inputDefinition, new ArrayInput(['--option_optional_default' => 'default'], $inputDefinition)], 'option_optional_default_value' => [$inputDefinition, new ArrayInput(['--option_optional_default' => 'value'], $inputDefinition), '--option_optional_default \'value\''], 'option_array_default_array_default' => [$inputDefinition, new ArrayInput(['--option_array_default_array' => []], $inputDefinition)], 'option_array_default_array_value' => [$inputDefinition, new ArrayInput(['--option_array_default_array' => ['value1', 'value2']], $inputDefinition), '--option_array_default_array \'value1\' --option_array_default_array \'value2\''], 'option_none_default' => [$inputDefinition, new ArrayInput([], $inputDefinition)], 'option_none_default_value' => [$inputDefinition, new ArrayInput(['--option_none' => 'any'], $inputDefinition), '--option_none'], 'out_folder_skip' => [$inputDefinition, new ArrayInput(['--out' => ['folder', 'std']], $inputDefinition), '', ['out']], 'out_folder' => [$inputDefinition, new ArrayInput(['--out' => ['folder', 'std']], $inputDefinition), '--out \'folder/59adaf3f0820898ecf0da97ceab30eab\' --out \'std\'']];
}
示例2: configure
/**
* @see Symfony\Component\Console\Command.Command::configure()
*/
protected function configure()
{
$definition = new InputDefinition();
$definition->addArgument(new InputArgument('namespace', InputArgument::REQUIRED, 'The namespace to process'));
$definition->addArgument(new InputArgument('path', InputArgument::REQUIRED, 'The path the namespace can be found in'));
$definition->addOption(new InputOption('output', 'o', InputOption::VALUE_REQUIRED, 'The path to output the ReST files', 'build'));
$definition->addOption(new InputOption('title', 't', InputOption::VALUE_REQUIRED, 'An alternate title for the top level namespace', null));
$definition->addOption(new InputOption('exclude', 'x', InputOption::VALUE_REQUIRED, 'Semicolon separated namespaces to ignore', null));
$definition->addOption(new InputOption('filters', 'f', InputOption::VALUE_REQUIRED, 'Semicolon separated filename filters to apply', null));
$this->setName('process')->setDescription('Processes a directory of PHPDoc documented code into ReST')->setHelp('The process command works recursively on a directory of PHP code.')->setDefinition($definition);
}
示例3: buildInputDefinition
private function buildInputDefinition()
{
$inputDefinition = new InputDefinition();
$inputDefinition->addArgument(new InputArgument('uno', InputArgument::REQUIRED));
$inputDefinition->addOption(new InputOption('due', null, InputOption::VALUE_NONE));
return $inputDefinition;
}
示例4: setUp
public function setUp()
{
parent::setUp();
$this->template = $this->prophesize(TemplateInterface::class);
$inputDef = new InputDefinition();
$inputDef->addOption(new InputOption('test-option', null, InputOption::VALUE_OPTIONAL));
$this->input = new ArrayInput(['--test-option' => null], $inputDef);
$this->output = new BufferedOutput();
$this->application = $this->getApplication();
$styleHelper = $this->application->getHelperSet()->get('gush_style');
$styleHelper->setInput($this->input);
$styleHelper->setOutput($this->output);
$this->helper = new TemplateHelper($styleHelper, $this->application);
$this->helper->setInput($this->input);
}
示例5: run
/**
* @inheritdoc
*/
public static function run($request, $response, $args)
{
global $argv;
$container = static::getApp()->getContainer();
$pathResolver = $container['pathResolver'];
$filesystem = new Filesystem();
$creator = new MigrationCreator($filesystem);
$definition = new InputDefinition();
$definition->addArgument(new InputArgument('name', InputArgument::REQUIRED));
$definition->addOption(new InputOption('table', 't', InputOption::VALUE_OPTIONAL));
$input = new ArgvInput(array_slice($argv, 1), $definition);
$output = new ConsoleOutput();
$path = $pathResolver->getAlias('@db/migrations');
$name = $input->getArgument('name');
$table = $input->getOption('table');
$file = pathinfo($creator->create($name, $path, $table), PATHINFO_FILENAME);
\dump($file);
}
示例6: createForFormType
/**
* @param string|\Symfony\Component\Form\FormTypeInterface $formType
* @param array &$resources
*
* @return InputDefinition
*/
public function createForFormType($formType, array &$resources = [])
{
$resources[] = new FileResource(__FILE__);
$form = $this->formFactory->create($formType);
$actualFormType = $form->getConfig()->getType()->getInnerType();
$reflection = new \ReflectionObject($actualFormType);
$resources[] = new FileResource($reflection->getFileName());
$inputDefinition = new InputDefinition();
foreach ($form->all() as $name => $field) {
if (!$this->isFormFieldSupported($field)) {
continue;
}
$type = InputOption::VALUE_REQUIRED;
$default = $field->getConfig()->getOption('data', null);
$description = FormUtil::label($field);
$inputDefinition->addOption(new InputOption($name, null, $type, $description, $default));
}
return $inputDefinition;
}
示例7: filterByOriginalDefinition
/**
* @param InputInterface $input
* @param $appDefinition
* @return ArrayInput
*/
public function filterByOriginalDefinition(InputInterface $input, $appDefinition)
{
$newDefinition = new InputDefinition();
$newInput = new ArrayInput(array(), $newDefinition);
foreach ($input->getArguments() as $name => $value) {
if (!$appDefinition->hasArgument($name)) {
$newDefinition->addArgument($this->getDefinition()->getArgument($name));
if (!empty($value)) {
$newInput->setArgument($name, $value);
}
}
}
foreach ($input->getOptions() as $name => $value) {
if (!$appDefinition->hasOption($name)) {
$newDefinition->addOption($this->getDefinition()->getOption($name));
if (!empty($value)) {
$newInput->setOption($name, $value);
}
}
}
return $newInput;
}
示例8: configureInputDefinition
/**
* Add options to a Symfony Console input definition.
*
* @param InputDefinition $definition
*/
public function configureInputDefinition(InputDefinition $definition)
{
foreach ($this->fields as $field) {
$definition->addOption($field->getAsOption());
}
}
示例9: bindSignature
protected function bindSignature()
{
$signatureParts = new SignatureParts($this->signature);
$signature = $signatureParts->getSignatureWithoutCommandName();
list($name, $arguments, $options) = Parser::parse($signature);
$this->name = $name;
$inputDefinition = new InputDefinition();
foreach ($arguments as $argument) {
$inputDefinition->addArgument($argument);
}
foreach ($options as $option) {
$inputDefinition->addOption($option);
}
$inputWithoutHandlerName = explode(' ', $this->request->text, 2)[1] ?? '';
$this->input = new StringInput($inputWithoutHandlerName);
$this->inputDefinition = $inputDefinition;
try {
$this->input->bind($inputDefinition);
} catch (RuntimeException $exception) {
return false;
}
return true;
}
示例10: InputDefinition
<?php
require __DIR__ . '/vendor/autoload.php';
use Elastica\Client;
use Elastica\Document;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
$inputDefinition = new InputDefinition();
$inputDefinition->addArgument(new InputArgument('host', InputArgument::REQUIRED));
$inputDefinition->addArgument(new InputArgument('tree', InputArgument::REQUIRED));
$options = [['port', null, InputOption::VALUE_REQUIRED, '', 9200], ['index', null, InputOption::VALUE_REQUIRED, '', 'test'], ['type', null, InputOption::VALUE_REQUIRED, '', 'test'], ['treeLevels', null, InputOption::VALUE_REQUIRED, '', null], ['precision', null, InputOption::VALUE_REQUIRED, '', null], ['tab', null, InputOption::VALUE_NONE], ['bulk-size', null, InputOption::VALUE_REQUIRED, '', 10]];
foreach ($options as $option) {
$inputDefinition->addOption(new InputOption($option[0], $option[1], $option[2], $option[3], $option[4]));
}
$argvInput = new ArgvInput($argv, $inputDefinition);
$main = function () use($argvInput) {
$host = $argvInput->getArgument('host');
$port = $argvInput->getOption('port');
$indexName = $argvInput->getOption('index');
$typeName = $argvInput->getOption('type');
$treeLevels = $argvInput->getOption('treeLevels');
$precision = $argvInput->getOption('precision');
$tree = $argvInput->getArgument('tree');
$bulkSize = $argvInput->getOption('bulk-size');
$tab = $argvInput->getOption('tab');
if (!in_array($tree, ['quadtree', 'geohash'])) {
throw new \Exception(sprintf('Supported tree types are quadtree and geohash, "%s" given.', $tree));
}
if (!isset($treeLevels) && !isset($precision)) {
示例11: getDefinition
/**
* Add the retrieved options and arguments to a definition
*
* @return InputDefinition
*/
public function getDefinition()
{
if (!$this->initialized) {
$this->initialize();
}
$definition = new InputDefinition();
foreach ($this->definitions as $from => $info) {
$config = $info['config'];
$required = array_key_exists('required', $config) && $config['required'];
if ($info['type'] === 'option') {
$mode = array_key_exists('mode', $config) ? $config['mode'] : InputOption::VALUE_OPTIONAL;
if ($required) {
$mode |= InputOption::VALUE_REQUIRED;
}
if (in_array('array', explode('|', $config['type']), true)) {
$mode |= InputOption::VALUE_IS_ARRAY;
}
if (preg_match('/(^|\\|)bool(ean)?($|\\|)/', $config['type'])) {
if (strpos($config['type'], '|')) {
$mode |= InputOption::VALUE_NONE;
} else {
$mode = InputOption::VALUE_NONE;
}
}
$definition->addOption(new InputOption($from, array_key_exists('shortcut', $config) ? $config['shortcut'] : null, $mode, $config['label'], array_key_exists('default', $config) ? $config['default'] : null));
} else {
$mode = array_key_exists('mode', $config) ? $config['mode'] : InputArgument::OPTIONAL;
if ($required) {
$mode |= InputArgument::REQUIRED;
}
if (in_array('array', explode('|', $config['type']), true)) {
$mode |= InputArgument::IS_ARRAY;
}
$definition->addArgument(new InputArgument($from, $mode, $config['label'], array_key_exists('default', $config) ? $config['default'] : null));
}
}
return $definition;
}
示例12: configureInput
/**
* Add options to a command's input definition.
*
* @param InputDefinition $definition
*/
public static function configureInput(InputDefinition $definition)
{
$description = 'The date format (as a PHP date format string)';
$option = new InputOption('date-fmt', null, InputOption::VALUE_REQUIRED, $description, self::DEFAULT_DATE_FORMAT);
$definition->addOption($option);
}
示例13: addOption
/**
* Adds an option.
*
* @param string $name The option name
* @param string $shortcut The shortcut (can be null)
* @param int $mode The option mode: One of the InputOption::VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for InputOption::VALUE_REQUIRED or InputOption::VALUE_NONE)
*
* @return Command The current instance
*/
public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
{
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
return $this;
}
示例14: addFormatOption
/**
* Add the --format option to a command's input definition.
*
* @param InputDefinition $definition
*/
public static function addFormatOption(InputDefinition $definition)
{
$description = 'The output format ("table", "csv", or "tsv")';
$option = new InputOption('format', null, InputOption::VALUE_REQUIRED, $description, 'table');
$definition->addOption($option);
}
示例15: setInputDefinition
/**
* @param InputDefinition $inputDefinition
*/
private function setInputDefinition(InputDefinition $inputDefinition)
{
$inputDefinition->addOption(new InputOption('log-level', 'l', InputOption::VALUE_REQUIRED, 'Override the Monolog logging level for this execution of the command. Valid values: ' . implode(', ', array_keys(Logger::getLevels()))));
$inputDefinition->addOption(new InputOption('log-filename', null, InputOption::VALUE_REQUIRED, 'Specify a different file (relative to the kernel log directory) to send file logs to'));
$inputDefinition->addOption(new InputOption('locking', null, InputOption::VALUE_REQUIRED, 'Whether or not this execution needs to acquire a ' . ' lock that ensures that the command is only being run once concurrently. Valid values: on, off'));
}