/** * 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; }
/** * Is Valid * * @see Zend_Validate_Interface */ public function isValid($value) { $this->_setValue($value); if (!is_array($value)) { $this->_error(self::NOT_ARRAY); return false; } $validCount = 0; $invalidCount = 0; $invalidMax = count($value) - $this->_threshold + 1; foreach ($this->value as $v) { if ($this->_validator->isValid($v)) { ++$validCount; } else { ++$invalidCount; } if ($validCount >= $this->_threshold) { return true; } if ($invalidCount >= $invalidMax) { $this->_error(self::TOO_FEW); return false; } } return true; }
/** * Magic Get * * @param string $property * @return mixed * @throws Zend_Validate_Exception */ public function __get($property) { if (empty($this->_errors)) { return $this->validator->__get($property); } else { return parent::__get($property); } }
/** * * @param array $event * @return bool */ public function accept($event) { if (null === $this->_key) { $validationData = $event; } elseif (isset($event[$this->_key])) { $validationData = $event[$this->_key]; } else { $message = 'key "' . $this->_key . '" not found in event'; throw new Robo47_Log_Filter_Exception($message); } if (true === $this->_not) { return !$this->_validator->isValid($validationData); } else { return $this->_validator->isValid($validationData); } }
/** * Is Valid * * @see Zend_Validate_Interface */ public function isValid($value) { $this->_setValue($value); if (!is_array($value)) { $this->_error(self::NOT_ARRAY); return false; } $validCount = 0; foreach ($this->value as $v) { if ($this->_validator->isValid($v)) { $validCount++; } if ($validCount > $this->_threshold) { $this->_error(self::TOO_MANY); return false; } } return true; }
/** * 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; }
/** * 2015-04-05 * Пока никем извне класса не используется, но будет. * @used-by checkProperty() * @param mixed $value * @param \Zend_Validate_Interface $validator * @throws \Df\Core\Exception * @return bool */ public static function validate($value, \Zend_Validate_Interface $validator) { return is_null($value) && isset($validator->{self::$SKIP_ON_NULL}) && $validator->{self::$SKIP_ON_NULL} || $validator->isValid($value); }
/** * Generate parameters for a validator rule * @param string $class The name of the validator class * @param Zend_Validate_Interface $validator the validator * @return string */ protected function _generateValidatorParameters($class, Zend_Validate_Interface $validator) { $params = '{}'; switch ($class) { case 'Zend_Validate_Alnum': case 'Zend_Validate_Alpha': $params = '{ allowWhiteSpace: ' . ($validator->allowWhiteSpace ? 'true' : 'false') . ' } '; break; case 'Zend_Validate_Between': $params = '{ min: ' . $validator->getMin() . ', max: ' . $validator->getMax() . ' } '; break; case 'Zend_Validate_Date': $params = '{ format: ' . $validator->getFormat() . ' } '; break; case 'Zend_Validate_GreaterThan': $params = '{ min: ' . $validator->getMin() . ' } '; break; } return $params; }
/** * @param \Zend_Validate_Interface $validator * @param mixed $paramValue * @param int $paramOrdering * @param int $stackLevel * @return void * @throws \Exception */ public static function validateParam(\Zend_Validate_Interface $validator, $paramValue, $paramOrdering, $stackLevel = 1) { if (!$validator->isValid($paramValue)) { self::raiseErrorParam($validatorClass = get_class($validator), $messages = $validator->getMessages(), $paramOrdering, ++$stackLevel); } }
/** * Call the decorated validator. This method is called by Opus_Validate_AbstractMate::isValid(). * * @param mixed $value Value to validate. * @return boolean Whatever the decorated validators isValid() method returns. */ protected function _isValid($value) { return $this->_decorated->isValid($value); }
/** * Return cookie value "as is" as long as it exists and passes the validation * * @param string $cookieName * @param Zend_Validate_Interface $validator * @return string|bool */ protected static function _getValidCookieValue($cookieName, Zend_Validate_Interface $validator) { if (isset($_COOKIE[$cookieName]) && $validator->isValid($_COOKIE[$cookieName])) { return $_COOKIE[$cookieName]; } return false; }
/** * @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()))); }
/** * Calls the adaptee's isValid method * * @see Specification/Streamwide_Specification_Abstract#isSatisfiedBy($candidate) */ public function isSatisfiedBy($candidate) { return $this->_adaptee->isValid($candidate); }
/** * 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); }