當前位置: 首頁>>代碼示例>>PHP>>正文


PHP InputArgument::isRequired方法代碼示例

本文整理匯總了PHP中Symfony\Component\Console\Input\InputArgument::isRequired方法的典型用法代碼示例。如果您正苦於以下問題:PHP InputArgument::isRequired方法的具體用法?PHP InputArgument::isRequired怎麽用?PHP InputArgument::isRequired使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Console\Input\InputArgument的用法示例。


在下文中一共展示了InputArgument::isRequired方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: 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

示例3: testConstructor

 public function testConstructor()
 {
     $argument = new InputArgument('foo');
     $this->assertEquals('foo', $argument->getName(), '__construct() takes a name as its first argument');
     // mode argument
     $argument = new InputArgument('foo');
     $this->assertFalse($argument->isRequired(), '__construct() gives a "InputArgument::OPTIONAL" mode by default');
     $argument = new InputArgument('foo', null);
     $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
     $argument = new InputArgument('foo', InputArgument::OPTIONAL);
     $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
     $argument = new InputArgument('foo', InputArgument::REQUIRED);
     $this->assertTrue($argument->isRequired(), '__construct() can take "InputArgument::REQUIRED" as its mode');
     try {
         $argument = new InputArgument('foo', '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('Argument mode "ANOTHER_ONE" is not valid.', $e->getMessage());
     }
     try {
         $argument = new InputArgument('foo', -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('Argument mode "-1" is not valid.', $e->getMessage());
     }
 }
開發者ID:paulodacosta,項目名稱:LearnFlash,代碼行數:28,代碼來源:InputArgumentTest.php

示例4: testModes

 public function testModes()
 {
     $argument = new InputArgument('foo');
     $this->assertFalse($argument->isRequired(), '__construct() gives a "InputArgument::OPTIONAL" mode by default');
     $argument = new InputArgument('foo', null);
     $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
     $argument = new InputArgument('foo', InputArgument::OPTIONAL);
     $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
     $argument = new InputArgument('foo', InputArgument::REQUIRED);
     $this->assertTrue($argument->isRequired(), '__construct() can take "InputArgument::REQUIRED" as its mode');
 }
開發者ID:Ener-Getick,項目名稱:symfony,代碼行數:11,代碼來源:InputArgumentTest.php

示例5: addArgument

 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:itillawarra,項目名稱:cmfive,代碼行數:21,代碼來源:InputDefinition.php

示例6: 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

示例7: describeInputArgument

 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     $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 $this->output($dom, $options);
 }
開發者ID:ccq18,項目名稱:EduSoho,代碼行數:20,代碼來源:XmlDescriptor.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: 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

示例12: 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


注:本文中的Symfony\Component\Console\Input\InputArgument::isRequired方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。