コード例 #1
0
 public function testHashOption()
 {
     $options = array('foo' => 42, 'bar' => 4.2, 'baz' => array('o_O', false, null, '42' => 42, array()));
     $formatterOptions = new FormatterOptions($options);
     foreach (array_keys($options) as $option) {
         $this->assertTrue($formatterOptions->hasOption($option));
     }
     $this->assertFalse($formatterOptions->hasOption('ohi'));
     $this->assertFalse($formatterOptions->hasOption('Foo'));
 }
 /**
  * @param FormatterOptions $options
  *
  * @throws InvalidArgumentException
  * @return LabelDescriptionLookup
  */
 public function getLabelDescriptionLookup(FormatterOptions $options)
 {
     if ($options->hasOption(self::OPT_LABEL_DESCRIPTION_LOOKUP)) {
         return $this->getLabelDescriptionLookupFromOptions($options);
     } elseif ($options->hasOption(self::OPT_LANGUAGE_FALLBACK_CHAIN)) {
         return $this->newLanguageFallbackLabelDescriptionLookup($options);
     } elseif ($options->hasOption(ValueFormatter::OPT_LANG)) {
         return $this->newLanguageLabelDescriptionLookup($options);
     } else {
         throw new InvalidArgumentException('OPT_LANG, OPT_LANGUAGE_FALLBACK_CHAIN, ' . 'or OPT_LABEL_DESCRIPTION_LOOKUP must be set in FormatterOptions.');
     }
 }
 /**
  * Initializes the options keys ValueFormatter::OPT_LANG and
  * FormatterLabelDescriptionLookupFactory::OPT_LANGUAGE_FALLBACK_CHAIN if they are not yet set.
  *
  * @param FormatterOptions $options The options to modify.
  *
  * @throws InvalidArgumentException
  * @todo  : Sort out how the desired language is specified. We have two language options,
  *        each accepting different ways of specifying the language. That's not good.
  * @todo: this shouldn't be public at all. Perhaps factor it out into a helper class.
  */
 public function applyLanguageDefaults(FormatterOptions $options)
 {
     $options->defaultOption(ValueFormatter::OPT_LANG, $this->defaultLanguage->getCode());
     $lang = $options->getOption(ValueFormatter::OPT_LANG);
     if (!is_string($lang)) {
         throw new InvalidArgumentException('The value of OPT_LANG must be a language code. For a fallback chain, use OPT_LANGUAGE_FALLBACK_CHAIN.');
     }
     $fallbackOption = FormatterLabelDescriptionLookupFactory::OPT_LANGUAGE_FALLBACK_CHAIN;
     if (!$options->hasOption($fallbackOption)) {
         $fallbackMode = LanguageFallbackChainFactory::FALLBACK_ALL;
         $options->setOption($fallbackOption, $this->languageFallbackChainFactory->newFromLanguageCode($lang, $fallbackMode));
     }
     if (!$options->getOption($fallbackOption) instanceof LanguageFallbackChain) {
         throw new InvalidArgumentException('The value of OPT_LANGUAGE_FALLBACK_CHAIN must be ' . 'an instance of LanguageFallbackChain.');
     }
 }