本文整理汇总了PHP中Symfony\Component\Console\Input\InputDefinition类的典型用法代码示例。如果您正苦于以下问题:PHP InputDefinition类的具体用法?PHP InputDefinition怎么用?PHP InputDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InputDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setOptionDescription
private function setOptionDescription(InputDefinition $definition, $name, $description)
{
$argument = $definition->getOption($name);
if ($argument instanceof InputOption) {
$argument->setDescription($description);
}
}
示例2: describeInputDefinition
/**
*
* {@inheritdoc}
*
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
foreach ($definition->getArguments() as $argument) {
$totalWidth = max($totalWidth, strlen($argument->getName()));
}
if ($definition->getArguments()) {
$this->writeText('<comment>Arguments:</comment>', $options);
$this->writeText("\n");
foreach ($definition->getArguments() as $argument) {
$this->describeInputArgument($argument, array_merge($options, array('total_width' => $totalWidth)));
$this->writeText("\n");
}
}
if ($definition->getArguments() && $definition->getOptions()) {
$this->writeText("\n");
}
if ($definition->getOptions()) {
$laterOptions = array();
$this->writeText('<comment>Options:</comment>', $options);
foreach ($definition->getOptions() as $option) {
if (strlen($option->getShortcut()) > 1) {
$laterOptions[] = $option;
continue;
}
$this->writeText("\n");
$this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
}
foreach ($laterOptions as $option) {
$this->writeText("\n");
$this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
}
}
}
示例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: init
/**
* @param InputDefinition $inputDefinition
* @param InputInterface $input
*/
public function init(InputDefinition $inputDefinition, InputInterface $input)
{
$options = new ProcessOptionCollection();
foreach ($inputDefinition->getOptions() as $optionName => $inputOption) {
$optionValue = $input->getOption($optionName);
if ($inputOption->getDefault() != $optionValue) {
switch (true) {
case in_array($optionName, $this->skipOptions):
$option = null;
break;
case $inputOption->isArray() && $optionName == 'out':
$option = new ProcessOptionOut($optionName, $optionValue);
break;
case $inputOption->isArray():
$option = new ProcessOptionArray($optionName, $optionValue);
break;
case $inputOption->isValueRequired():
case $inputOption->isValueOptional():
$option = new ProcessOptionScalar($optionName, $optionValue);
break;
default:
$option = new ProcessOption($optionName);
}
if ($option) {
$options->set($option);
}
}
}
$this->optionCollection = $options;
}
示例5: getInputDefinition
/**
* Get an InputDefinition formed by the arguments provided
*
* Effectively provides a passthrough for any input arguments provided
*
* @param array $args Arguments
* @return InputDefinition
*/
protected function getInputDefinition(array $args)
{
$definition = new InputDefinition();
foreach ($args as $field => $value) {
$definition->addArgument(new InputArgument($field));
}
return $definition;
}
示例6: 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\'']];
}
示例7: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$nameWidth = 0;
foreach ($definition->getOptions() as $option) {
$nameLength = strlen($option->getName()) + 2;
if ($option->getShortcut()) {
$nameLength += strlen($option->getShortcut()) + 3;
}
$nameWidth = max($nameWidth, $nameLength);
}
foreach ($definition->getArguments() as $argument) {
$nameWidth = max($nameWidth, strlen($argument->getName()));
}
++$nameWidth;
if ($definition->getArguments()) {
$this->writeText('<comment>Arguments:</comment>', $options);
$this->writeText("\n");
foreach ($definition->getArguments() as $argument) {
$this->describeInputArgument($argument, array_merge($options, array('name_width' => $nameWidth)));
$this->writeText("\n");
}
}
if ($definition->getArguments() && $definition->getOptions()) {
$this->writeText("\n");
}
if ($definition->getOptions()) {
$this->writeText('<comment>Options:</comment>', $options);
$this->writeText("\n");
foreach ($definition->getOptions() as $option) {
$this->describeInputOption($option, array_merge($options, array('name_width' => $nameWidth)));
$this->writeText("\n");
}
}
}
示例8: 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);
}
示例9: getInputDefinitionData
private function getInputDefinitionData(InputDefinition $definition)
{
$inputArguments = array();
foreach ($definition->getArguments() as $name => $argument) {
$inputArguments[$name] = $this->getInputArgumentData($argument);
}
$inputOptions = array();
foreach ($definition->getOptions() as $name => $option) {
$inputOptions[$name] = $this->getInputOptionData($option);
}
return array('arguments' => $inputArguments, 'options' => $inputOptions);
}
示例10: testConfigureSystemCommand
public function testConfigureSystemCommand()
{
$name = 'test_base_command';
$description = 'test for base command creation';
$keywords = 'base commands creation test';
$arguments = array('username' => array('description' => 'linux username'));
$options = 'options';
$expectedArguments = new InputDefinition();
$expectedArguments->addArgument(new InputArgument('username', InputArgument::REQUIRED, $arguments['username']['description']));
$systemCommand = new SystemCommand($name, $description, $keywords, $arguments, $options);
$this->assertEquals($expectedArguments, $systemCommand->getDefinition());
}
示例11: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$inputArguments = array();
foreach ($definition->getArguments() as $name => $argument) {
$inputArguments[$name] = $this->describeInputArgument($argument, array('as_array' => true));
}
$inputOptions = array();
foreach ($definition->getOptions() as $name => $option) {
$inputOptions[$name] = $this->describeInputOption($option, array('as_array' => true));
}
return $this->output(array('arguments' => $inputArguments, 'options' => $inputOptions), $options);
}
示例12: configure
protected function configure()
{
parent::configure();
$definition = new InputDefinition();
$definition->setDefinition(array(new InputArgument('username', InputArgument::REQUIRED, 'The username'), new InputArgument('role', InputArgument::OPTIONAL, 'The role'), new InputOption('user-system', null, InputOption::VALUE_REQUIRED, 'The user-system to use'), new InputOption('super', null, InputOption::VALUE_NONE, 'Instead specifying role, use this to quickly add the super administrator role')));
$this->setDefinition($definition);
$this->setHelp(<<<EOT
The <info>fos:user:demote</info> command demotes a user by removing a role
<info>php app/console fos:user:demote --user-system=acme_user matthieu ROLE_CUSTOM</info>
<info>php app/console fos:user:demote --user-system=acme_user --super matthieu</info>
EOT
);
}
示例13: getInputDefinitionDocument
/**
* @param InputDefinition $definition
*
* @return \DOMDocument
*/
public function getInputDefinitionDocument(InputDefinition $definition)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($definitionXML = $dom->createElement('definition'));
$definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
foreach ($definition->getArguments() as $argument) {
$this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument));
}
$definitionXML->appendChild($optionsXML = $dom->createElement('options'));
foreach ($definition->getOptions() as $option) {
$this->appendDocument($optionsXML, $this->getInputOptionDocument($option));
}
return $dom;
}
示例14: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($definitionXML = $dom->createElement('definition'));
$definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
foreach ($definition->getArguments() as $argument) {
$this->appendDocument($argumentsXML, $this->describeInputArgument($argument, array('as_dom' => true)));
}
$definitionXML->appendChild($optionsXML = $dom->createElement('options'));
foreach ($definition->getOptions() as $option) {
$this->appendDocument($optionsXML, $this->describeInputOption($option, array('as_dom' => true)));
}
return $this->output($dom, $options);
}
示例15: 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);
}