/** * Validates the values in the $values array and returns a ValidationResult. * * @param array $values * @param string $context * @return ValidationResult */ public function validate(array $values, $context = self::DEFAULT_CONTEXT) { $isValid = true; $messageStack = $this->buildMessageStack($context); $this->output = new Container(); $input = new Container($values); foreach ($this->chains[$context] as $chain) { /** @var Chain $chain */ $isValid = $chain->validate($messageStack, $input, $this->output) && $isValid; } return new ValidationResult($isValid, $this->messageStack->getMessages(), $this->output->getArrayCopy()); }
/** * Validates the values in the $values array and appends messages to $messageStack. Returns the result as a bool. * * @param MessageStack $messageStack * @param Container $input * @param Container $output * @return bool */ public function validate(MessageStack $messageStack, Container $input, Container $output) { $valid = true; $output->set($this->key, $input->get($this->key)); foreach ($this->rules as $rule) { $rule->setMessageStack($messageStack); $rule->setParameters($this->key, $this->name); $valid = $rule->isValid($this->key, $input) && $valid; if ($rule->shouldBreakChain()) { return $valid; } } return $valid; }
/** * Determines whether or not the value may be empty. * * @param Container $input * @return bool */ protected function allowEmpty(Container $input) { if (isset($this->allowEmptyCallback)) { $this->allowEmpty = call_user_func($this->allowEmptyCallback, $input->getArrayCopy()); } return $this->allowEmpty; }
/** * Validates the value according to this rule, and returns the result as a bool. * * @param string $key * @param Container $input * @return bool */ public function isValid($key, Container $input) { $this->values = $input->getArrayCopy(); return parent::isValid($key, $input); }
/** * Determines whether or not the value of $key is valid in the array $values and returns the result as a bool. * * @param string $key * @param Container $input * @return bool */ public function isValid($key, Container $input) { return $this->validate($input->get($key)); }
/** * Determines if the value is required. * * @param Container $input * @return bool */ protected function isRequired(Container $input) { if (isset($this->requiredCallback)) { $this->required = call_user_func_array($this->requiredCallback, [$input->getArrayCopy()]); } return $this->required; }