Exemple #1
0
 /**
  * Get Messages
  *
  * Proxies to the decorated validator when this doesn't have any raised 
  * errors of its own.
  *
  * @returns array
  */
 public function getMessages()
 {
     if (empty($this->_messages)) {
         return $this->validator->getMessages();
     } else {
         return $this->_messages;
     }
 }
 /**
  * Used to bring in messages and errors from aggregated validates
  *
  * @param Zend_Validate_Interface $validate
  * return Zend_Validate_Interface
  */
 protected function _addValidateMessagesAndErrors($validate)
 {
     foreach ($validate->getMessages() as $code => $message) {
         $this->_messages[$code] = $message;
     }
     foreach ($validate->getErrors() as $error) {
         $this->_errors[] = $error;
     }
     return $this;
 }
 /**
  * Checks if the values of the two form elements fulfill the relation.
  *
  * @param mixed $value
  * @param array(string=>string)|null $context
  * @return boolean True if the element relation is fulfilled, false otherwise.
  */
 public function isValid($value, $context = null)
 {
     $this->_setValue($value);
     $this->rawCompareValue = null;
     if ($context === null) {
         $this->_error(self::NO_CONTEXT);
         return false;
     }
     if (!is_array($context)) {
         $this->_error(self::INVALID_CONTEXT);
         return false;
     }
     if (!isset($context[$this->getCompareName()])) {
         $this->_error(self::NO_COMPARE_VALUE);
         return false;
     }
     $this->rawCompareValue = $context[$this->getCompareName()];
     if (!$this->relation->isValid($value, $this->rawCompareValue)) {
         $this->addMessages($this->relation->getMessages());
         return false;
     }
     return true;
 }
Exemple #4
0
 /**
  * @param \Zend_Validate_Interface $validator
  * @param mixed $value
  * @param int $stackLevel
  * @return void
  * @throws \Exception
  */
 public static function validateValue(\Zend_Validate_Interface $validator, $value, $stackLevel = 1)
 {
     if (!$validator->isValid($value)) {
         /** @var string $messagesS */
         $messagesS = df_cc_n($validator->getMessages());
         /** @var string $validatorClass */
         $validatorClass = get_class($validator);
         self::throwException("Значение переменной забраковано проверяющим «{$validatorClass}»." . "\nСообщения проверяющего:\n{$messagesS}", $stackLevel);
     }
 }
 /**
  * @param object $object
  * @param string $propertyName
  * @param mixed $propertyValue
  * @param \Zend_Validate_Interface $failedValidator
  */
 public function __construct($object, $propertyName, $propertyValue, \Zend_Validate_Interface $failedValidator)
 {
     parent::__construct(sprintf("«%s»: значение %s недопустимо для свойства «%s».\nСообщение проверяющего:\n%s", get_class($object), df_debug_type($propertyValue), $propertyName, df_cc_n($failedValidator->getMessages())));
 }
 /**
  * Raise
  *
  * Raises an error message for the given field. The validator instance that 
  * failed the field is needed to retrieve the right error message.
  * 
  * If not using its default error messages, the validator is used to 
  * substitute the placeholders in the custom error message templates.  
  * Therefore, the given validator instance must have a getMessageVariables() 
  * method in that case.
  *
  * @see Zend_Validate_Builder_ErrorManager_Interface
  *
  * @param string Field to raise an error message for
  * @param Zend_Validate_Interface Validator instance that failed the field
  * @returns void
  * @throws none
  */
 public function raise($field, Zend_Validate_Interface $val)
 {
     // Get *all* the errors raised by the validator
     $messages = $val->getMessages();
     $valClass = get_class($val);
     // If there are no custom messages defined, use the default messages
     // returned by the validator.
     if (empty($this->_messages) || empty($this->_messages[$field]) || empty($this->_messages[$field][$valClass])) {
         $this->_raised[$field][$valClass] = $messages;
     } else {
         $templates = array_intersect_key($this->_messages[$field][$valClass], $messages);
         foreach ($templates as $reason => $msg) {
             $this->_raised[$field][$valClass][$reason] = $this->_createMessage($msg, $val);
         }
     }
 }
 /**
  * Extracts the error messages from the validator and return them as string.
  *
  * @param Zend_Validate_Interface $validator
  * @return string
  */
 protected function toMessage(Zend_Validate_Interface $validator)
 {
     $messages = $validator->getMessages();
     return implode(PHP_EOL, $messages);
 }