示例#1
0
 public function execute()
 {
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Translate/Adapter/Array.php';
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale.php';
     try {
         // check if the WP locale is valid otherwise set it to default
         $locale = IfwPsn_Wp_Proxy_Blog::getLanguage();
         if (!in_array($locale, $this->_supportedLanguages)) {
             $locale = 'en_US';
         }
         $translator = new IfwPsn_Vendor_Zend_Translate('IfwPsn_Vendor_Zend_Translate_Adapter_Array', $this->_adapter->getPluginManager()->getPathinfo()->getRootLib() . 'IfwPsn/Zend/Form/resources/languages', $locale, array('scan' => IfwPsn_Vendor_Zend_Translate::LOCALE_DIRECTORY));
         // set the validation translator
         IfwPsn_Vendor_Zend_Validate_Abstract::setDefaultTranslator($translator);
     } catch (Exception $e) {
         // do nothing. if something failed, we just have no translation for Zend_Validate
     }
 }
示例#2
0
 /**
  * Sets a default translation object for all validation objects
  *
  * @param IfwPsn_Vendor_Zend_Translate|IfwPsn_Vendor_Zend_Translate_Adapter|null $translator
  */
 public static function setDefaultTranslator($translator = null)
 {
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Validate/Abstract.php';
     IfwPsn_Vendor_Zend_Validate_Abstract::setDefaultTranslator($translator);
 }
示例#3
0
 /**
  * Sets the validation failure message template for a particular key
  * Adds the ability to set messages to the attached hostname validator
  *
  * @param  string $messageString
  * @param  string $messageKey     OPTIONAL
  * @return IfwPsn_Vendor_Zend_Validate_Abstract Provides a fluent interface
  * @throws IfwPsn_Vendor_Zend_Validate_Exception
  */
 public function setMessage($messageString, $messageKey = null)
 {
     if ($messageKey === null) {
         $this->_options['hostname']->setMessage($messageString);
         parent::setMessage($messageString);
         return $this;
     }
     if (!isset($this->_messageTemplates[$messageKey])) {
         $this->_options['hostname']->setMessage($messageString, $messageKey);
     }
     $this->_messageTemplates[$messageKey] = $messageString;
     return $this;
 }
示例#4
0
 /**
  * Validate element value
  *
  * If a translation adapter is registered, any error messages will be
  * translated according to the current locale, using the given error code;
  * if no matching translation is found, the original message will be
  * utilized.
  *
  * Note: The *filtered* value is validated.
  *
  * @param  mixed $value
  * @param  mixed $context
  * @return boolean
  */
 public function isValid($value, $context = null)
 {
     $this->setValue($value);
     $value = $this->getValue();
     if (('' === $value || null === $value) && !$this->isRequired() && $this->getAllowEmpty()) {
         return true;
     }
     if ($this->isRequired() && $this->autoInsertNotEmptyValidator() && !$this->getValidator('NotEmpty')) {
         $validators = $this->getValidators();
         $notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true);
         array_unshift($validators, $notEmpty);
         $this->setValidators($validators);
     }
     // Find the correct translator. IfwPsn_Vendor_Zend_Validate_Abstract::getDefaultTranslator()
     // will get either the static translator attached to IfwPsn_Vendor_Zend_Validate_Abstract
     // or the 'IfwPsn_Vendor_Zend_Translate' from IfwPsn_Vendor_Zend_Registry.
     if (IfwPsn_Vendor_Zend_Validate_Abstract::hasDefaultTranslator() && !IfwPsn_Vendor_Zend_Form::hasDefaultTranslator()) {
         $translator = IfwPsn_Vendor_Zend_Validate_Abstract::getDefaultTranslator();
         if ($this->hasTranslator()) {
             // only pick up this element's translator if it was attached directly.
             $translator = $this->getTranslator();
         }
     } else {
         $translator = $this->getTranslator();
     }
     $this->_messages = array();
     $this->_errors = array();
     $result = true;
     $isArray = $this->isArray();
     foreach ($this->getValidators() as $key => $validator) {
         if (method_exists($validator, 'setTranslator')) {
             if (method_exists($validator, 'hasTranslator')) {
                 if (!$validator->hasTranslator()) {
                     $validator->setTranslator($translator);
                 }
             } else {
                 $validator->setTranslator($translator);
             }
         }
         if (method_exists($validator, 'setDisableTranslator')) {
             $validator->setDisableTranslator($this->translatorIsDisabled());
         }
         if ($isArray && is_array($value)) {
             $messages = array();
             $errors = array();
             if (empty($value)) {
                 if ($this->isRequired() || !$this->isRequired() && !$this->getAllowEmpty()) {
                     $value = '';
                 }
             }
             foreach ((array) $value as $val) {
                 if (!$validator->isValid($val, $context)) {
                     $result = false;
                     if ($this->_hasErrorMessages()) {
                         $messages = $this->_getErrorMessages();
                         $errors = $messages;
                     } else {
                         $messages = array_merge($messages, $validator->getMessages());
                         $errors = array_merge($errors, $validator->getErrors());
                     }
                 }
             }
             if ($result) {
                 continue;
             }
         } elseif ($validator->isValid($value, $context)) {
             continue;
         } else {
             $result = false;
             if ($this->_hasErrorMessages()) {
                 $messages = $this->_getErrorMessages();
                 $errors = $messages;
             } else {
                 $messages = $validator->getMessages();
                 $errors = array_keys($messages);
             }
         }
         $result = false;
         $this->_messages = array_merge($this->_messages, $messages);
         $this->_errors = array_merge($this->_errors, $errors);
         if ($validator->zfBreakChainOnFailure) {
             break;
         }
     }
     // If element manually flagged as invalid, return false
     if ($this->_isErrorForced) {
         return false;
     }
     return $result;
 }
示例#5
0
 /**
  * Sets the maximum allowed message length
  *
  * @param integer $length
  */
 public static function setMessageLength($length = -1)
 {
     self::$_messageLength = $length;
 }