addCommandName() public method

Adds a command name to the built format.
public addCommandName ( CommandName $commandName ) : static
$commandName CommandName The command name to add.
return static The current instance.
Ejemplo n.º 1
0
 public function testGetDefinitionWithBaseDefinition()
 {
     $this->baseFormatBuilder->addCommandName($server = new CommandName('server'));
     $this->baseFormatBuilder->addArgument($argument1 = new Argument('argument1'));
     $this->baseFormatBuilder->addOption($option1 = new Option('option1'));
     $this->builder = new ArgsFormatBuilder($baseDefinition = $this->baseFormatBuilder->getFormat());
     $this->builder->addCommandName($add = new CommandName('add'));
     $this->builder->addArgument($argument2 = new Argument('argument2'));
     $this->builder->addArgument($argument3 = new Argument('argument3'));
     $this->builder->addOption($option2 = new Option('option2'));
     $this->builder->addOption($option3 = new Option('option3'));
     $definition = $this->builder->getFormat();
     $this->assertSame($baseDefinition, $definition->getBaseFormat());
     // base command names are returned first
     $this->assertSame(array($server, $add), $definition->getCommandNames());
     // base arguments are returned first
     $this->assertSame(array('argument1' => $argument1, 'argument2' => $argument2, 'argument3' => $argument3), $definition->getArguments());
     // base options are returned last
     $this->assertSame(array('option2' => $option2, 'option3' => $option3, 'option1' => $option1), $definition->getOptions());
 }
Ejemplo n.º 2
0
 /**
  * Creates a format builder for a set of arguments and options.
  *
  * @param array      $elements   The arguments and options to add to the
  *                               builder.
  * @param ArgsFormat $baseFormat The base format.
  *
  * @return ArgsFormatBuilder The created builder.
  */
 private function createBuilderForElements(array $elements, ArgsFormat $baseFormat = null)
 {
     $builder = new ArgsFormatBuilder($baseFormat);
     foreach ($elements as $element) {
         if ($element instanceof CommandName) {
             $builder->addCommandName($element);
         } elseif ($element instanceof CommandOption) {
             $builder->addCommandOption($element);
         } elseif ($element instanceof Option) {
             $builder->addOption($element);
         } elseif ($element instanceof Argument) {
             $builder->addArgument($element);
         } else {
             throw new InvalidArgumentException(sprintf('Expected instances of CommandName, CommandOption, ' . 'Option or Argument. Got: %s', is_object($element) ? get_class($element) : gettype($element)));
         }
     }
     return $builder;
 }