/**
  * Add a sfCommandArgument objects.
  *
  * @param sfCommandArgument $argument A sfCommandArgument object
  */
 public function addArgument(sfCommandArgument $argument)
 {
     if (isset($this->arguments[$argument->getName()])) {
         throw new sfCommandException(sprintf('An argument with name "%s" already exist.', $argument->getName()));
     }
     if ($this->hasAnArrayArgument) {
         throw new sfCommandException('Cannot add an argument after an array argument.');
     }
     if ($argument->isRequired() && $this->hasOptional) {
         throw new sfCommandException('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;
 }
Esempio n. 2
0
$argument = new sfCommandArgument('foo', sfCommandArgument::REQUIRED);
$t->is($argument->isRequired(), true, '__construct() can take "sfCommandArgument::PARAMETER_REQUIRED" as its mode');
try {
    $argument = new sfCommandArgument('foo', 'ANOTHER_ONE');
    $t->fail('__construct() throws an sfCommandException if the mode is not valid');
} catch (sfCommandException $e) {
    $t->pass('__construct() throws an sfCommandException if the mode is not valid');
}
// ->isArray()
$t->diag('->isArray()');
$argument = new sfCommandArgument('foo', sfCommandArgument::IS_ARRAY);
$t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array');
$argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY);
$t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array');
$argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL);
$t->ok(!$argument->isArray(), '->isArray() returns false if the argument can not be an array');
// ->getHelp()
$t->diag('->getHelp()');
$argument = new sfCommandArgument('foo', null, 'Some help');
$t->is($argument->getHelp(), 'Some help', '->getHelp() return the message help');
// ->getDefault()
$t->diag('->getDefault()');
$argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL, '', 'default');
$t->is($argument->getDefault(), 'default', '->getDefault() return the default value');
// ->setDefault()
$t->diag('->setDefault()');
$argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL, '', 'default');
$argument->setDefault(null);
$t->ok(null === $argument->getDefault(), '->setDefault() can reset the default value by passing null');
$argument->setDefault('another');
$t->is($argument->getDefault(), 'another', '->setDefault() changes the default value');