/** * 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); }
$t->pass('->getOption() throws an exception if the option name does not exist'); } // ->hasOption() $t->diag('->hasOption()'); $optionSet = new sfCommandOptionSet(); $optionSet->addOptions(array($foo)); $t->is($optionSet->hasOption('foo'), true, '->hasOption() returns true if a sfCommandOption exists for the given name'); $t->is($optionSet->hasOption('bar'), false, '->hasOption() returns false if a sfCommandOption exists for the given name'); // ->hasShortcut() $t->diag('->hasShortcut()'); $optionSet = new sfCommandOptionSet(); $optionSet->addOptions(array($foo)); $t->is($optionSet->hasShortcut('f'), true, '->hasShortcut() returns true if a sfCommandOption exists for the given shortcut'); $t->is($optionSet->hasShortcut('b'), false, '->hasShortcut() returns false if a sfCommandOption exists for the given shortcut'); // ->getOptionForShortcut() $t->diag('->getOptionForShortcut()'); $optionSet = new sfCommandOptionSet(); $optionSet->addOptions(array($foo)); $t->is($optionSet->getOptionForShortcut('f'), $foo, '->getOptionForShortcut() returns a sfCommandOption by its shortcut'); try { $optionSet->getOptionForShortcut('l'); $t->fail('->getOption() throws an exception if the shortcut does not exist'); } catch (sfCommandException $e) { $t->pass('->getOption() throws an exception if the shortcut does not exist'); } // ->getDefaults() $t->diag('->getDefaults()'); $optionSet = new sfCommandOptionSet(); $optionSet->addOptions(array(new sfCommandOption('foo1', null, sfCommandOption::PARAMETER_NONE), new sfCommandOption('foo2', null, sfCommandOption::PARAMETER_REQUIRED), new sfCommandOption('foo3', null, sfCommandOption::PARAMETER_REQUIRED, '', 'default'), new sfCommandOption('foo4', null, sfCommandOption::PARAMETER_OPTIONAL), new sfCommandOption('foo5', null, sfCommandOption::PARAMETER_OPTIONAL, '', 'default'), new sfCommandOption('foo6', null, sfCommandOption::PARAMETER_OPTIONAL | sfCommandOption::IS_ARRAY), new sfCommandOption('foo7', null, sfCommandOption::PARAMETER_OPTIONAL | sfCommandOption::IS_ARRAY, '', array(1, 2)))); $defaults = array('foo1' => null, 'foo2' => null, 'foo3' => 'default', 'foo4' => null, 'foo5' => 'default', 'foo6' => array(), 'foo7' => array(1, 2)); $t->is($optionSet->getDefaults(), $defaults, '->getDefaults() returns the default values for all options');