示例#1
0
 /**
  * {@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");
         }
     }
 }
示例#2
0
 /**
  * @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;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 protected function describeInputDefinition(InputDefinition $definition, array $options = array())
 {
     if ($showArguments = count($definition->getArguments()) > 0) {
         $this->write('### Arguments:');
         foreach ($definition->getArguments() as $argument) {
             $this->write("\n\n");
             $this->write($this->describeInputArgument($argument));
         }
     }
     if (count($definition->getOptions()) > 0) {
         if ($showArguments) {
             $this->write("\n\n");
         }
         $this->write('### Options:');
         foreach ($definition->getOptions() as $option) {
             $this->write("\n\n");
             $this->write($this->describeInputOption($option));
         }
     }
 }
示例#4
0
 public function testAsXml()
 {
     $definition = new InputDefinition(array(new InputArgument('foo', InputArgument::OPTIONAL, 'The foo argument'), new InputArgument('baz', InputArgument::OPTIONAL, 'The baz argument', true), new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('bar')), new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'), new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar')));
     $this->assertXmlStringEqualsXmlFile(self::$fixtures . '/definition_asxml.txt', $definition->asXml(), '->asText() returns a textual representation of the InputDefinition');
 }
示例#5
0
 /**
  * @param InputDefinition $definition
  *
  * @return array
  */
 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);
 }