예제 #1
0
 public function __construct($optionName, $templateName, tubepress_api_options_PersistenceInterface $persistence, tubepress_api_http_RequestParametersInterface $requestParams, tubepress_api_template_TemplatingInterface $templating, tubepress_api_options_ReferenceInterface $optionReference)
 {
     $this->_optionProvider = $optionReference;
     $this->_templateName = $templateName;
     $this->_optionName = $optionName;
     if (!$this->_optionProvider->optionExists($optionName)) {
         throw new InvalidArgumentException(sprintf('Could not find option with name "%s"', $optionName));
     }
     $label = $this->_optionProvider->getUntranslatedLabel($optionName);
     $description = $this->_optionProvider->getUntranslatedDescription($optionName);
     parent::__construct($optionName, $persistence, $requestParams, $templating, $label, $description);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function get($optionName)
 {
     if (array_key_exists($optionName, $this->_ephemeralOptions)) {
         return $this->_ephemeralOptions[$optionName];
     }
     try {
         return $this->_persistence->fetch($optionName);
     } catch (InvalidArgumentException $e) {
         if ($this->_optionReference->optionExists($optionName) && !$this->_optionReference->isMeantToBePersisted($optionName)) {
             return null;
         }
         throw $e;
     }
 }
 private function _setLegacyVariables(array &$templateVars)
 {
     $metaNames = $this->_getAllMetaOptionNames();
     $shouldShow = array();
     $labels = array();
     foreach ($metaNames as $metaName) {
         if (!$this->_optionReference->optionExists($metaName)) {
             $shouldShow[$metaName] = false;
             $labels[$metaName] = '';
             continue;
         }
         $shouldShow[$metaName] = $this->_context->get($metaName);
         $untranslatedLabel = $this->_optionReference->getUntranslatedLabel($metaName);
         $labels[$metaName] = $this->_translator->trans($untranslatedLabel);
     }
     $templateVars[tubepress_api_const_template_Variable::META_SHOULD_SHOW] = $shouldShow;
     $templateVars[tubepress_api_const_template_Variable::META_LABELS] = $labels;
 }
예제 #4
0
 public function onOption(tubepress_api_event_EventInterface $event)
 {
     $errors = $event->getSubject();
     $optionName = $event->getArgument('optionName');
     $optionValue = $event->getArgument('optionValue');
     if (!$this->_optionsReference->optionExists($optionName)) {
         $error = $this->_translator->trans('No option with name "%s".');
         //>(translatable)<
         $error = sprintf($error, $optionName);
         $errors[] = $error;
         $event->setSubject($errors);
         return;
     }
     if ($this->_optionsReference->isBoolean($optionName) && !is_bool($optionValue)) {
         $error = $this->_translator->trans('"%s" can only be "true" or "false". You supplied "%s".');
         //>(translatable)<
         $error = sprintf($error, $this->_getLabel($optionName), $optionValue);
         $errors[] = $error;
         $event->setSubject($errors);
         return;
     }
     $acceptableValues = $this->_acceptableValues->getAcceptableValues($optionName);
     if ($acceptableValues !== null) {
         if ($this->_langUtils->isAssociativeArray($acceptableValues)) {
             $values = array_keys($acceptableValues);
         } else {
             $values = array_values($acceptableValues);
         }
         if (!in_array($optionValue, $values)) {
             $error = $this->_translator->trans('"%s" must be one of "%s". You supplied "%s".');
             //>(translatable)<
             $error = sprintf($error, $this->_getLabel($optionName), implode(', ', $values), $optionValue);
             $errors[] = $error;
             $event->setSubject($errors);
         }
     }
 }
예제 #5
0
 private function _deepConvertBooleans(array &$candidate)
 {
     foreach ($candidate as $key => $value) {
         if (is_array($value)) {
             $this->_deepConvertBooleans($value);
             $candidate[$key] = $value;
         }
         if (!$this->_optionsReference->optionExists($key)) {
             continue;
         }
         if (!$this->_optionsReference->isBoolean($key)) {
             continue;
         }
         $candidate[$key] = (bool) $value;
     }
 }