Exemplo n.º 1
0
 /**
  * Returns the option value for a given option name.
  *
  * @param string $name The option name
  *
  * @return mixed The option value
  *
  * @throws InvalidArgumentException When option given doesn't exist
  */
 public function getOption($name)
 {
     if (!$this->definition->hasOption($name)) {
         throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
     }
     return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
 }
Exemplo n.º 2
0
 private function setOptionDescription(InputDefinition $definition, $name, $description)
 {
     $argument = $definition->getOption($name);
     if ($argument instanceof InputOption) {
         $argument->setDescription($description);
     }
 }
Exemplo n.º 3
0
 /**
  * Returns an InputOption by name.
  *
  * @param string $name The InputOption name
  *
  * @return InputOption A InputOption object
  *
  * @api
  */
 public function getOption($name)
 {
     if ('no-' === substr($name, 0, 3)) {
         $switch = parent::getOption('[no-]' . substr($name, 3));
         $switch->setDefault(false);
         return $switch;
     }
     if (parent::hasOption('[no-]' . $name)) {
         $switch = parent::getOption('[no-]' . $name);
         $switch->setDefault(true);
         return $switch;
     }
     return parent::getOption($name);
 }
Exemplo n.º 4
0
 /**
  * @expectedException        \InvalidArgumentException
  * @expectedExceptionMessage The "--bar" option does not exist.
  */
 public function testGetInvalidOption()
 {
     $this->initializeOptions();
     $definition = new InputDefinition(array($this->foo));
     $definition->getOption('bar');
 }
Exemplo n.º 5
0
 public function testGetOption()
 {
     $this->initializeOptions();
     $definition = new InputDefinition(array($this->foo));
     $this->assertEquals($this->foo, $definition->getOption('foo'), '->getOption() returns a InputOption by its name');
     try {
         $definition->getOption('bar');
         $this->fail('->getOption() throws an exception if the option name does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->getOption() throws an exception if the option name does not exist');
         $this->assertEquals('The "--bar" option does not exist.', $e->getMessage());
     }
 }