Author: Jakub Tománek
Inheritance: implements Jyxo\Input\ValidatorInterface
コード例 #1
0
ファイル: Conditional.php プロジェクト: JerryCR/php-2
 /**
  * Validates a value.
  *
  * @param mixed $value Input value
  * @return boolean
  */
 public function isValid($value)
 {
     // Validation is performed only if the condition is fulfilled
     if (true === $this->checkCondition($value)) {
         return parent::isValid($value);
     }
     // No validation -> the value is valid
     $this->value = $value;
     return true;
 }
コード例 #2
0
ファイル: Fluent.php プロジェクト: jyxo/php
 /**
  * Checks a chain.
  *
  * @param \Jyxo\Input\Chain $chain Validation chain
  * @param mixed $value Input value
  * @param mixed $default Default value to be used in case the validation fails
  * @param string $name Chain name to be used in the error array
  * @return boolean
  */
 private function checkChain(\Jyxo\Input\Chain $chain, &$value, $default, string $name = null) : bool
 {
     $valid = true;
     if ($chain->isValid($value)) {
         $value = $chain->getValue();
     } elseif (null !== $default) {
         $value = $default;
     } else {
         $valid = false;
         // If we have $name set, we want an associative array
         $errors = empty($name) ? $chain->getErrors() : [$name => $chain->getErrors()];
         $this->errors = array_merge($this->errors, $errors);
     }
     return $valid;
 }