/** * Filter the redirect url * * @param mixed $value * @return string|null */ public function filter($value) { if (!$this->validator->isValid($value)) { return null; } return urldecode(filter_var($value, FILTER_SANITIZE_URL)); }
/** * checks to see if the value passed is * valid input for the ColumnDefinition * injected * * @param mixed $value * * @return boolean */ public function isValid($value) { if ($this->validator) { return $this->validator->isValid($value); } else { return false; } }
/** * {@inheritDoc} */ public function getRules(ValidatorInterface $validator, ElementInterface $element = null) { $token = $validator->getToken(); if (strpos($element->getName(), "[") !== false) { $token = preg_replace('#\\[[^\\]]+\\]$#i', "[" . $token . "]", $element->getName()); } return array('equalTo' => '[name="' . $token . '"]'); }
/** * Inject a validator instance with the registered translator * * @param ValidatorInterface $validator * @return void */ public function injectTranslator($validator) { if ($validator instanceof Translator\TranslatorAwareInterface) { $locator = $this->getServiceLocator(); if ($locator && $locator->has('MvcTranslator')) { $validator->setTranslator($locator->get('MvcTranslator')); } } }
/** * @param array $options * @return RadioGroup */ public function setValueOptions(array $options) { $this->valueOptions = $options; // Update InArrayValidator validator haystack if ($this->validator instanceof InArrayValidator) { $this->validator->setHaystack($this->getValueOptionsValues()); } return $this; }
/** * Get the validation rules * * @param \Zend\Validator\ValidatorInterface $validator * @param \Zend\Form\ElementInterface $element * @return array */ public function getRules(ValidatorInterface $validator, ElementInterface $element = null) { // Javascript doesn't support associative arrays. Therefore, check if the array is associative, // and if so, transform it to a non-associative one. if (array_keys($validator->getHaystack()) !== range(0, count($validator->getHaystack()) - 1)) { return array('in_array' => array_values($validator->getHaystack())); } return array('in_array' => (array) $validator->getHaystack()); }
/** * Do the validation * * @param mixed $value * @return boolean */ protected function validate($value) { return Match::on(Option::create($this->validator->isValid($value), false))->Monad_Option_Some(true)->Monad_Option_None(function () { $msgs = $this->validator->getMessages(); array_walk($msgs, function ($msg) { $this->messenger->add(new StringType($msg)); }); return false; })->value(); }
/** * {@inheritDoc} */ public function getMessages(ValidatorInterface $validator) { $messages = array(); if ($validator->getMin() > 0) { $messages['minlength'] = sprintf($this->translateMessage('At least %s characters are required'), $validator->getMin()); } if ($validator->getMax() > 0) { $messages['maxlength'] = sprintf($this->translateMessage('At most %s characters are allowed'), $validator->getMax()); } return $messages; }
/** * @param array $options * @return Select */ public function setValueOptions(array $options) { $this->valueOptions = $options; // Update InArrayValidator validator haystack if (null !== $this->validator) { if ($this->validator instanceof InArrayValidator) { $validator = $this->validator; } if ($this->validator instanceof ExplodeValidator && $this->validator->getValidator() instanceof InArrayValidator) { $validator = $this->validator->getValidator(); } if (!empty($validator)) { $validator->setHaystack($this->getValueOptionsValues()); } } return $this; }
/** * Returns TRUE to accept the message, FALSE to block it. * * @param array $event event data * @return bool */ public function filter(array $event) { return $this->validator->isValid($event['message']); }
/** * {@inheritDoc} */ public function getMessages(ValidatorInterface $validator) { return array('min' => sprintf($this->translateMessage('The input is not greater than %s'), $validator->getMin())); }
/** * @param mixed $value * @param CollectionInterface $collection * * @return bool */ public function __invoke($value, CollectionInterface $collection = null) { return $this->validator->isValid($value, $collection); }
/** * @param \Zend\Validator\ValidatorInterface $validator * @return mixed */ protected function getMax(\Zend\Validator\ValidatorInterface $validator) { return $validator->getInclusive() ? $validator->getMax() : $validator->getMax() - 1; }