/** * 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); }
$optionSet->getOptionForShortcut('f'); $t->fail('->setOptions() clears all sfCommandOption objects'); } catch (sfCommandException $e) { $t->pass('->setOptions() clears all sfCommandOption objects'); } // ->addOptions() $t->diag('->addOptions()'); $optionSet = new sfCommandOptionSet(); $optionSet->addOptions(array($foo)); $t->is($optionSet->getOptions(), array('foo' => $foo), '->addOptions() adds an array of sfCommandOption objects'); $optionSet->addOptions(array($bar)); $t->is($optionSet->getOptions(), array('foo' => $foo, 'bar' => $bar), '->addOptions() does not clear existing sfCommandOption objects'); // ->addOption() $t->diag('->addOption()'); $optionSet = new sfCommandOptionSet(); $optionSet->addOption($foo); $t->is($optionSet->getOptions(), array('foo' => $foo), '->addOption() adds a sfCommandOption object'); $optionSet->addOption($bar); $t->is($optionSet->getOptions(), array('foo' => $foo, 'bar' => $bar), '->addOption() adds a sfCommandOption object'); try { $optionSet->addOption($foo2); $t->fail('->addOption() throws a sfCommandException if the another option is already registered with the same name'); } catch (sfCommandException $e) { $t->pass('->addOption() throws a sfCommandException if the another option is already registered with the same name'); } try { $optionSet->addOption($foo1); $t->fail('->addOption() throws a sfCommandException if the another option is already registered with the same shortcut'); } catch (sfCommandException $e) { $t->pass('->addOption() throws a sfCommandException if the another option is already registered with the same shortcut'); }