Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function onSubmit()
 {
     $isBoolean = $this->_optionProvider->isBoolean($this->_optionName);
     $paramName = $this->getId();
     $requestParams = $this->getHttpRequestParameters();
     if ($isBoolean) {
         return $this->sendToStorage($this->_optionName, $requestParams->hasParam($paramName));
     }
     if (!$requestParams->hasParam($paramName)) {
         /* not submitted. */
         return null;
     }
     $value = $requestParams->getParamValue($paramName);
     return $this->sendToStorage($this->_optionName, $this->convertIncomingStringValueToStorageFormat($value));
 }
Ejemplo n.º 2
0
 private function _noChangeBetweenIncomingAndCurrent($optionName, $filteredValue)
 {
     $boolean = $this->_optionsReference->isBoolean($optionName);
     $currentValue = $this->fetch($optionName);
     if ($boolean) {
         return (bool) $filteredValue === (bool) $currentValue;
     }
     return $currentValue == $filteredValue;
 }
Ejemplo n.º 3
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);
         }
     }
 }
Ejemplo n.º 4
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;
     }
 }