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


PHP Input\InputArgument类代码示例

本文整理汇总了PHP中Symfony\Component\Console\Input\InputArgument的典型用法代码示例。如果您正苦于以下问题:PHP InputArgument类的具体用法?PHP InputArgument怎么用?PHP InputArgument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了InputArgument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSetDefault

 public function testSetDefault()
 {
     $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
     $argument->setDefault(null);
     $this->assertNull($argument->getDefault(), '->setDefault() can reset the default value by passing null');
     $argument->setDefault('another');
     $this->assertEquals('another', $argument->getDefault(), '->setDefault() changes the default value');
     $argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
     $argument->setDefault(array(1, 2));
     $this->assertEquals(array(1, 2), $argument->getDefault(), '->setDefault() changes the default value');
     try {
         $argument = new InputArgument('foo', InputArgument::REQUIRED);
         $argument->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value for a required argument');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
         $this->assertEquals('Cannot set a default value except for Parameter::OPTIONAL mode.', $e->getMessage());
     }
     try {
         $argument = new InputArgument('foo', InputArgument::IS_ARRAY);
         $argument->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
         $this->assertEquals('A default value for an array argument must be an array.', $e->getMessage());
     }
 }
开发者ID:rooster,项目名称:symfony,代码行数:27,代码来源:InputArgumentTest.php

示例2: promptMissingArgument

 /**
  * @param InputInterface $input
  * @param InputArgument  $argument
  */
 protected function promptMissingArgument(InputInterface $input, $argument)
 {
     $hasArgument = false;
     while (!$hasArgument) {
         $answer = $this->out->ask($argument->getDescription(), $argument->getDefault());
         if ($answer !== null) {
             $hasArgument = true;
             $input->setArgument($argument->getName(), $answer);
         } elseif (!$argument->isRequired()) {
             $hasArgument = true;
         }
     }
 }
开发者ID:natedrake,项目名称:fast-forward,代码行数:17,代码来源:InteractiveCommand.php

示例3: getArgumentMode

 /**
  * @param InputArgument $argument
  * @return int
  */
 private function getArgumentMode(InputArgument $argument)
 {
     $mode = 0;
     if ($argument->isRequired()) {
         $mode |= InputArgument::REQUIRED;
     }
     if ($argument->isArray()) {
         $mode |= InputArgument::IS_ARRAY;
     }
     if (!$argument->isRequired()) {
         $mode |= InputArgument::OPTIONAL;
     }
     return $mode;
 }
开发者ID:brainexe,项目名称:core,代码行数:18,代码来源:ConsoleCompilerPass.php

示例4: describeInputArgument

 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
         $default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($argument->getDefault()));
     } else {
         $default = '';
     }
     $totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName());
     $spacingWidth = $totalWidth - strlen($argument->getName()) + 2;
     $this->writeText(sprintf('  <info>%s</info>%s%s%s', $argument->getName(), str_repeat(' ', $spacingWidth), preg_replace('/\\s*[\\r\\n]\\s*/', "\n" . str_repeat(' ', $totalWidth + 17), $argument->getDescription()), $default), $options);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:14,代码来源:TextDescriptor.php

示例5: describeInputArgument

 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
         $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
     } else {
         $default = '';
     }
     $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());
     $this->writeText(sprintf(" <info>%-{$nameWidth}s</info> %s%s", $argument->getName(), str_replace("\n", "\n" . str_repeat(' ', $nameWidth + 2), $argument->getDescription()), $default), $options);
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:13,代码来源:TextDescriptor.php

示例6: addArgument

 /**
  * Adds an InputArgument object.
  *
  * @param InputArgument $argument An InputArgument object
  *
  * @throws LogicException When incorrect argument is given
  */
 public function addArgument(InputArgument $argument)
 {
     if (isset($this->arguments[$argument->getName()])) {
         throw new LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
     }
     if ($this->hasAnArrayArgument) {
         throw new LogicException('Cannot add an argument after an array argument.');
     }
     if ($argument->isRequired() && $this->hasOptional) {
         throw new LogicException('Cannot add a required argument after an optional one.');
     }
     if ($argument->isArray()) {
         $this->hasAnArrayArgument = true;
     }
     if ($argument->isRequired()) {
         ++$this->requiredCount;
     } else {
         $this->hasOptional = true;
     }
     $this->arguments[$argument->getName()] = $argument;
 }
开发者ID:saj696,项目名称:pipe,代码行数:28,代码来源:InputDefinition.php

示例7: describeInputArgument

 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = [])
 {
     $this->write('* **`' . $argument->getName() . "`**");
     $notes = [$argument->isRequired() ? "required" : "optional"];
     if ($argument->isArray()) {
         $notes[] = "multiple values allowed";
     }
     $this->write(' (' . implode('; ', $notes) . ')');
     $this->write("  \n  " . $argument->getDescription());
     if (!$argument->isRequired() && $argument->getDefault()) {
         $default = var_export($argument->getDefault(), true);
         $this->write("  \n  Default: `{$default}``");
     }
 }
开发者ID:drewmelck,项目名称:platformsh-cli,代码行数:17,代码来源:CustomMarkdownDescriptor.php

示例8: describeInputArgument

 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     $this->write('**' . $argument->getName() . ':**' . "\n\n" . '* Name: ' . ($argument->getName() ?: '<none>') . "\n" . '* Is required: ' . ($argument->isRequired() ? 'yes' : 'no') . "\n" . '* Is array: ' . ($argument->isArray() ? 'yes' : 'no') . "\n" . '* Description: ' . preg_replace('/\\s*\\R\\s*/', PHP_EOL . '  ', $argument->getDescription() ?: '<none>') . "\n" . '* Default: `' . str_replace("\n", '', var_export($argument->getDefault(), true)) . '`');
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:7,代码来源:MarkdownDescriptor.php

示例9: describeInputArgument

 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     return $this->output(array('name' => $argument->getName(), 'is_required' => $argument->isRequired(), 'is_array' => $argument->isArray(), 'description' => $argument->getDescription(), 'default' => $argument->getDefault()), $options);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:7,代码来源:JsonDescriptor.php

示例10: getInputArgumentData

 /**
  * @param InputArgument $argument
  *
  * @return array
  */
 private function getInputArgumentData(InputArgument $argument)
 {
     return array('name' => $argument->getName(), 'is_required' => $argument->isRequired(), 'is_array' => $argument->isArray(), 'description' => preg_replace('/\\s*\\R\\s*/', ' ', $argument->getDescription()), 'default' => $argument->getDefault());
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:9,代码来源:JsonDescriptor.php

示例11: getInputArgumentDocument

 /**
  * @param InputArgument $argument
  *
  * @return \DOMDocument
  */
 private function getInputArgumentDocument(InputArgument $argument)
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->appendChild($objectXML = $dom->createElement('argument'));
     $objectXML->setAttribute('name', $argument->getName());
     $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
     $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
     $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
     $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
     $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
     $defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
     foreach ($defaults as $default) {
         $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
         $defaultXML->appendChild($dom->createTextNode($default));
     }
     return $dom;
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:22,代码来源:XmlDescriptor.php

示例12: describeInputArgument

 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     return '**' . $argument->getName() . ':**' . "\n\n" . '* Name: ' . ($argument->getName() ?: '<none>') . "\n" . '* Is required: ' . ($argument->isRequired() ? 'yes' : 'no') . "\n" . '* Is array: ' . ($argument->isArray() ? 'yes' : 'no') . "\n" . '* Description: ' . ($argument->getDescription() ?: '<none>') . "\n" . '* Default: `' . str_replace("\n", '', var_export($argument->getDefault(), true)) . '`';
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:7,代码来源:MarkdownDescriptor.php

示例13: testSetDefaultWithArrayArgument

 /**
  * @expectedException        \LogicException
  * @expectedExceptionMessage A default value for an array argument must be an array.
  */
 public function testSetDefaultWithArrayArgument()
 {
     $argument = new InputArgument('foo', InputArgument::IS_ARRAY);
     $argument->setDefault('default');
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:9,代码来源:InputArgumentTest.php

示例14: describeInputArgument

 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     $this->write('#### `' . ($argument->getName() ?: '<none>') . "`\n\n" . ($argument->getDescription() ? preg_replace('/\\s*[\\r\\n]\\s*/', "\n", $argument->getDescription()) . "\n\n" : '') . '* Is required: ' . ($argument->isRequired() ? 'yes' : 'no') . "\n" . '* Is array: ' . ($argument->isArray() ? 'yes' : 'no') . "\n" . '* Default: `' . str_replace("\n", '', var_export($argument->getDefault(), true)) . '`');
 }
开发者ID:symfony,项目名称:symfony,代码行数:7,代码来源:MarkdownDescriptor.php

示例15: getDescription

 /**
  * {@inheritdoc}
  *
  * @codeCoverageIgnore
  */
 public function getDescription()
 {
     return $this->description ?: parent::getDescription();
 }
开发者ID:narrowspark,项目名称:framework,代码行数:9,代码来源:InputArgument.php


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