/** * 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; }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../../bootstrap/unit.php'; $t = new lime_test(16); // __construct() $t->diag('__construct()'); $argument = new sfCommandArgument('foo'); $t->is($argument->getName(), 'foo', '__construct() takes a name as its first argument'); // mode argument $argument = new sfCommandArgument('foo'); $t->is($argument->isRequired(), false, '__construct() gives a "sfCommandArgument::OPTIONAL" mode by default'); $argument = new sfCommandArgument('foo', null); $t->is($argument->isRequired(), false, '__construct() can take "sfCommandArgument::OPTIONAL" as its mode'); $argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL); $t->is($argument->isRequired(), false, '__construct() can take "sfCommandArgument::PARAMETER_OPTIONAL" as its mode'); $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()