Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Inheritance: implements ArrayAcces\ArrayAccess, implements IteratorAggregat\IteratorAggregate, implements Countabl\Countable
Exemplo n.º 1
0
 private static function filterDuplicates(array $names, CommandCollection $commands)
 {
     $filteredNames = array();
     foreach ($names as $nameToFilter) {
         // Check all existing names for duplicates
         foreach ($filteredNames as $filteredName) {
             // $nameToFilter is a duplicate - skip
             if ($commands->get($nameToFilter) === $commands->get($filteredName)) {
                 continue 2;
             }
         }
         $filteredNames[] = $nameToFilter;
     }
     return $filteredNames;
 }
Exemplo n.º 2
0
 public function testIterator()
 {
     $this->collection->add($ls = new Command(new CommandConfig('ls')));
     $this->collection->add($cd = new Command(new CommandConfig('cd')));
     $result = iterator_to_array($this->collection);
     $this->assertSame(array('ls' => $ls, 'cd' => $cd), $result);
 }
Exemplo n.º 3
0
 private function validateCommandName(CommandConfig $config)
 {
     $name = $config->getName();
     if (!$name) {
         throw CannotAddCommandException::nameEmpty();
     }
     if ($this->commands->contains($name)) {
         throw CannotAddCommandException::nameExists($name);
     }
 }
Exemplo n.º 4
0
 /**
  * @param RawArgs           $args
  * @param CommandCollection $namedCommands
  * @param string[]          $argumentsToTest
  * @param string[]          $optionsToTest
  *
  * @return ResolveResult
  */
 private function processArguments(RawArgs $args, CommandCollection $namedCommands, array $argumentsToTest, array $optionsToTest)
 {
     $currentCommand = null;
     // Parse the arguments for command names until we fail to find a
     // matching command
     foreach ($argumentsToTest as $name) {
         if (!$namedCommands->contains($name)) {
             break;
         }
         $nextCommand = $namedCommands->get($name);
         if ($nextCommand->getConfig() instanceof OptionCommandConfig) {
             break;
         }
         $currentCommand = $nextCommand;
         $namedCommands = $currentCommand->getNamedSubCommands();
     }
     if (!$currentCommand) {
         return null;
     }
     return $this->processOptions($args, $currentCommand, $optionsToTest);
 }
Exemplo n.º 5
0
 private function validateSubCommandName(SubCommandConfig $config)
 {
     $name = $config->getName();
     if (!$name) {
         throw CannotAddCommandException::nameEmpty();
     }
     if ($this->subCommands->contains($name)) {
         throw CannotAddCommandException::nameExists($name);
     }
     if ($config instanceof OptionCommandConfig) {
         if ($this->argsFormat->hasOption($name)) {
             throw CannotAddCommandException::optionExists($name);
         }
         if ($shortName = $config->getShortName()) {
             if ($this->subCommands->contains($shortName)) {
                 throw CannotAddCommandException::nameExists($name);
             }
             if ($this->argsFormat->hasOption($shortName)) {
                 throw CannotAddCommandException::optionExists($shortName);
             }
         }
     }
 }