Exemplo n.º 1
0
 protected function getAdditionalTemplateVariables()
 {
     $values = array();
     $map = $this->getOptionDescriptor()->getAcceptableValues();
     if (!tubepress_impl_util_LangUtils::isAssociativeArray($map)) {
         throw new InvalidArgumentException(sprintf('"%s" has a non-associative array set for its value map', $this->getOptionDescriptor()->getName()));
     }
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     foreach ($map as $key => $value) {
         $values[$key] = $messageService->_($value);
     }
     return array('choices' => $values);
 }
 /**
  * Gets the failure message of a name/value pair that has failed validation.
  *
  * @param string $optionName The option name
  * @param mixed  $candidate  The candidate option value
  *
  * @return mixed Null if the option passes validation, otherwise a string failure message.
  */
 public final function getProblemMessage($optionName, $candidate)
 {
     $optionDescriptorReferenceService = tubepress_impl_patterns_sl_ServiceLocator::getOptionDescriptorReference();
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $descriptor = $optionDescriptorReferenceService->findOneByName($optionName);
     if ($descriptor === null) {
         return sprintf('No option with name "%s".', $optionName);
         //>(translatable)<
     }
     if ($descriptor->hasValidValueRegex()) {
         if (preg_match_all($descriptor->getValidValueRegex(), (string) $candidate, $matches) >= 1 && $matches[0][0] === (string) $candidate) {
             return null;
         }
         return sprintf('Invalid value supplied for "%s".', $messageService->_($descriptor->getLabel()));
         //>(translatable)<
     }
     if ($descriptor->hasDiscreteAcceptableValues()) {
         $acceptableValues = $descriptor->getAcceptableValues();
         if (tubepress_impl_util_LangUtils::isAssociativeArray($acceptableValues)) {
             $values = array_keys($descriptor->getAcceptableValues());
         } else {
             $values = array_values($acceptableValues);
         }
         if (in_array($candidate, $values)) {
             return null;
         }
         return sprintf('"%s" must be one of "%s". You supplied "%s".', $messageService->_($descriptor->getLabel()), implode(', ', $values), $candidate);
     }
     if ($descriptor->isBoolean()) {
         if (is_bool($candidate)) {
             return null;
         }
         return sprintf('"%s" can only be "true" or "false". You supplied "%s".', $optionName, $candidate);
         //>(translatable)<
     }
     return null;
 }
Exemplo n.º 3
0
 public function setClassMap(array $map)
 {
     if (!empty($map) && !tubepress_impl_util_LangUtils::isAssociativeArray($map)) {
         throw new InvalidArgumentException('Class map must be an associative array');
     }
     $this->_classMap = $map;
 }