Ejemplo n.º 1
0
 /**
  * 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());
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }