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


PHP InputOption::getShortcut方法代码示例

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


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

示例1: describeInputOption

 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->appendChild($objectXML = $dom->createElement('option'));
     $objectXML->setAttribute('name', '--' . $option->getName());
     $pos = strpos($option->getShortcut(), '|');
     if (false !== $pos) {
         $objectXML->setAttribute('shortcut', '-' . substr($option->getShortcut(), 0, $pos));
         $objectXML->setAttribute('shortcuts', '-' . implode('|-', explode('|', $option->getShortcut())));
     } else {
         $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-' . $option->getShortcut() : '');
     }
     $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
     $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
     $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
     $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
     $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
     if ($option->acceptValue()) {
         $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
         $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
         if (!empty($defaults)) {
             foreach ($defaults as $default) {
                 $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
                 $defaultXML->appendChild($dom->createTextNode($default));
             }
         }
     }
     return $this->output($dom, $options);
 }
开发者ID:ccq18,项目名称:EduSoho,代码行数:32,代码来源:XmlDescriptor.php

示例2: describeInputOption

 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     $name = '--' . $option->getName();
     if ($option->getShortcut()) {
         $name .= '|-' . implode('|-', explode('|', $option->getShortcut())) . '';
     }
     $this->write('#### `' . $name . '`' . "\n\n" . ($option->getDescription() ? preg_replace('/\\s*[\\r\\n]\\s*/', "\n", $option->getDescription()) . "\n\n" : '') . '* Accept value: ' . ($option->acceptValue() ? 'yes' : 'no') . "\n" . '* Is value required: ' . ($option->isValueRequired() ? 'yes' : 'no') . "\n" . '* Is multiple: ' . ($option->isArray() ? 'yes' : 'no') . "\n" . '* Default: `' . str_replace("\n", '', var_export($option->getDefault(), true)) . '`');
 }
开发者ID:symfony,项目名称:symfony,代码行数:11,代码来源:MarkdownDescriptor.php

示例3: describeInputOption

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

示例4: testConstructor

 public function testConstructor()
 {
     $option = new InputOption('foo');
     $this->assertEquals('foo', $option->getName(), '__construct() takes a name as its first argument');
     $option = new InputOption('--foo');
     $this->assertEquals('foo', $option->getName(), '__construct() removes the leading -- of the option name');
     try {
         $option = new InputOption('foo', 'f', InputOption::VALUE_IS_ARRAY);
         $this->fail('->setDefault() throws an Exception if VALUE_IS_ARRAY option is used when an option does not accept a value');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->setDefault() throws an Exception if VALUE_IS_ARRAY option is used when an option does not accept a value');
         $this->assertEquals('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.', $e->getMessage());
     }
     // shortcut argument
     $option = new InputOption('foo', 'f');
     $this->assertEquals('f', $option->getShortcut(), '__construct() can take a shortcut as its second argument');
     $option = new InputOption('foo', '-f');
     $this->assertEquals('f', $option->getShortcut(), '__construct() removes the leading - of the shortcut');
     $option = new InputOption('foo');
     $this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default');
     // mode argument
     $option = new InputOption('foo', 'f');
     $this->assertFalse($option->acceptValue(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $this->assertFalse($option->isValueRequired(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $this->assertFalse($option->isValueOptional(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
     $option = new InputOption('foo', 'f', null);
     $this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_NONE);
     $this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_REQUIRED);
     $this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $this->assertTrue($option->isValueRequired(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
     $option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL);
     $this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
     $this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
     $this->assertTrue($option->isValueOptional(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
     try {
         $option = new InputOption('foo', 'f', 'ANOTHER_ONE');
         $this->fail('__construct() throws an Exception if the mode is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '__construct() throws an Exception if the mode is not valid');
         $this->assertEquals('Option mode "ANOTHER_ONE" is not valid.', $e->getMessage());
     }
     try {
         $option = new InputOption('foo', 'f', -1);
         $this->fail('__construct() throws an Exception if the mode is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '__construct() throws an Exception if the mode is not valid');
         $this->assertEquals('Option mode "-1" is not valid.', $e->getMessage());
     }
 }
开发者ID:laiello,项目名称:masfletes,代码行数:56,代码来源:InputOptionTest.php

示例5: describeInputOption

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

示例6: describeInputOption

 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = [])
 {
     $this->write('* **`--' . $option->getName() . "`**");
     if ($shortcut = $option->getShortcut()) {
         $this->write(" (`-" . implode('|-', explode('|', $shortcut)) . "`)");
     }
     $notes = [];
     if ($option->isArray()) {
         $notes[] = 'multiple values allowed';
     } elseif ($option->acceptValue()) {
         $notes[] = 'expects a value';
     }
     if ($notes) {
         $this->write(' (' . implode('; ', $notes) . ')');
     }
     if ($description = $option->getDescription()) {
         $this->write("  \n  " . $description);
     }
     if ($option->acceptValue() && $option->getDefault()) {
         $default = var_export($option->getDefault(), true);
         $this->write("  \n  Default: `{$default}`");
     }
 }
开发者ID:drewmelck,项目名称:platformsh-cli,代码行数:26,代码来源:CustomMarkdownDescriptor.php

示例7: describeInputOption

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

示例8: describeInputOption

 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     return $this->output(array('name' => '--' . $option->getName(), 'shortcut' => $option->getShortcut() ? '-' . implode('|-', explode('|', $option->getShortcut())) : '', 'accept_value' => $option->acceptValue(), 'is_value_required' => $option->isValueRequired(), 'is_multiple' => $option->isArray(), 'description' => $option->getDescription(), 'default' => $option->getDefault()), $options);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:7,代码来源:JsonDescriptor.php

示例9: getInputOptionData

 /**
  * @param InputOption $option
  *
  * @return array
  */
 private function getInputOptionData(InputOption $option)
 {
     return array('name' => '--' . $option->getName(), 'shortcut' => $option->getShortcut() ? '-' . implode('|-', explode('|', $option->getShortcut())) : '', 'accept_value' => $option->acceptValue(), 'is_value_required' => $option->isValueRequired(), 'is_multiple' => $option->isArray(), 'description' => preg_replace('/\\s*\\R\\s*/', ' ', $option->getDescription()), 'default' => $option->getDefault());
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:9,代码来源:JsonDescriptor.php

示例10: addOption

 /**
  * Adds an InputOption object.
  *
  * @param InputOption $option An InputOption object
  *
  * @throws LogicException When option given already exist
  *
  * @api
  */
 public function addOption(InputOption $option)
 {
     if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
         throw new LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
     }
     if ($option->getShortcut()) {
         foreach (explode('|', $option->getShortcut()) as $shortcut) {
             if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
                 throw new LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut));
             }
         }
     }
     $this->options[$option->getName()] = $option;
     if ($option->getShortcut()) {
         foreach (explode('|', $option->getShortcut()) as $shortcut) {
             $this->shortcuts[$shortcut] = $option->getName();
         }
     }
 }
开发者ID:hichammoad,项目名称:symfony,代码行数:28,代码来源:InputDefinition.php

示例11: equals

 /**
  * Checks whether the given option equals this one.
  *
  * @param InputOption $option option to compare
  *
  * @return bool
  */
 public function equals(InputOption $option)
 {
     return $option->getName() === $this->getName() && $option->getShortcut() === $this->getShortcut() && $option->getDefault() === $this->getDefault() && $option->isArray() === $this->isArray() && $option->isValueRequired() === $this->isValueRequired() && $option->isValueOptional() === $this->isValueOptional();
 }
开发者ID:saj696,项目名称:pipe,代码行数:11,代码来源:InputOption.php

示例12: inputOptionSetDescription

 protected static function inputOptionSetDescription($inputOption, $description)
 {
     // Recover the 'mode' value, because Symfony is stubborn
     $mode = 0;
     if ($inputOption->isValueRequired()) {
         $mode |= InputOption::VALUE_REQUIRED;
     }
     if ($inputOption->isValueOptional()) {
         $mode |= InputOption::VALUE_OPTIONAL;
     }
     if ($inputOption->isArray()) {
         $mode |= InputOption::VALUE_IS_ARRAY;
     }
     if (!$mode) {
         $mode = InputOption::VALUE_NONE;
     }
     $inputOption = new InputOption($inputOption->getName(), $inputOption->getShortcut(), $mode, $description, $inputOption->getDefault());
     return $inputOption;
 }
开发者ID:consolidation,项目名称:annotated-command,代码行数:19,代码来源:AnnotatedCommand.php


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