/** * Dynamically adds options to this task based on the current route. * * @param sfCommandManager $commandManager * @param array $options Options as read from commandline * * @return void * @see sfTask */ protected function process(sfCommandManager $commandManager, $options) { $commandManager->process($options); if (array_key_exists('application', $commandManager->getArgumentValues()) && array_key_exists('sf_route', $commandManager->getArgumentValues())) { $application = $commandManager->getArgumentValue('application'); $routeName = $commandManager->getArgumentValue('sf_route'); $configuration = $this->createConfiguration($application, 'prod'); $this->route = sfImageTransformExtraPluginConfiguration::getRoute($routeName, $configuration); $routeVariables = array_keys($this->route->getVariables()); $this->options = array(); $optionSet = new sfCommandOptionSet(); foreach ($commandManager->getErrors() as $error) { if (preg_match('/"--([\\w-_]+)"/', $error, $matches) && in_array($matches[1], $routeVariables)) { $option = new sfCommandOption($matches[1], null, sfCommandOption::PARAMETER_OPTIONAL, '', null); $this->options[] = $option; $optionSet->addOption($option); } } $commandManager->setOptionSet($optionSet); } parent::process($commandManager, $options); }
protected function process(sfCommandManager $commandManager, $options) { $commandManager->process($options); if (!$commandManager->isValid()) { throw new sfCommandArgumentsException(sprintf("The execution of task \"%s\" failed.\n- %s", $this->getFullName(), implode("\n- ", $commandManager->getErrors()))); } }
$manager->process('--foo'); $t->ok(!$manager->isValid(), '->isValid() returns false if the options are not valid'); $t->is(count($manager->getErrors()), 1, '->getErrors() returns an array of errors'); $optionSet = new sfCommandOptionSet(array(new sfCommandOption('foo', 'f', sfCommandOption::PARAMETER_REQUIRED))); $manager = new sfCommandManager(null, $optionSet); $manager->process('-f'); $t->ok(!$manager->isValid(), '->isValid() returns false if the options are not valid'); $t->is(count($manager->getErrors()), 1, '->getErrors() returns an array of errors'); $optionSet = new sfCommandOptionSet(array(new sfCommandOption('foo', null, sfCommandOption::PARAMETER_NONE))); $manager = new sfCommandManager(null, $optionSet); $manager->process('--foo="bar"'); $t->ok(!$manager->isValid(), '->isValid() returns false if the options are not valid'); $t->is(count($manager->getErrors()), 1, '->getErrors() returns an array of errors'); $manager = new sfCommandManager(); $manager->process('--bar'); $t->ok(!$manager->isValid(), '->isValid() returns false if the options are not valid'); $t->is(count($manager->getErrors()), 1, '->getErrors() returns an array of errors'); $manager = new sfCommandManager(); $manager->process('-b'); $t->ok(!$manager->isValid(), '->isValid() returns false if the options are not valid'); $t->is(count($manager->getErrors()), 1, '->getErrors() returns an array of errors'); $manager = new sfCommandManager(); $manager->process('--bar="foo"'); $t->ok(!$manager->isValid(), '->isValid() returns false if the options are not valid'); $t->is(count($manager->getErrors()), 1, '->getErrors() returns an array of errors');