Ejemplo n.º 1
0
 public function validate($data)
 {
     parent::validate($data);
     if (preg_match("/" . str_replace("/", "\\/", $this->value) . "/", $data) === 0) {
         $this->throwException("ValueException", "The data did not match the pattern " . (empty($this->format) ? "({$this->value})" : "for {$this->format}"), $data);
     }
 }
Ejemplo n.º 2
0
 public function validate($data)
 {
     parent::validate($data);
     foreach ($this->value as $field) {
         if (!isset($data->{$field})) {
             $this->throwException("RequirementException", "A required field was missing", $field);
         }
     }
 }
Ejemplo n.º 3
0
 public function validate($data)
 {
     parent::validate($data);
     $copy = $data;
     foreach ($data as $key => $value) {
         foreach ($copy as $key2 => $check) {
             if ($value === $check || is_object($value) && $value == $check) {
                 $this->throwException("ValueException", "The data contained values that aren't unique");
             }
         }
         // no need to check this key against any others
         // remove it from the check array to improve performance
         unset($copy[$key]);
     }
 }
Ejemplo n.º 4
0
 public function validate($data)
 {
     parent::validate($data);
     $float = $data / $this->value;
     $int = (int) $float;
     /**
      * we have to the epsilon method of comparison because floating point numbers are imprecise
      * and comparing them will give unexpected results.
      * I won't implement a relative Epsilon or ULP method here as that would be overkill, but it's
      * something to consider if we start finding this type of bug
      *
      * @link http://www.php.net/manual/en/language.types.float.php
      * @link http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
      */
     $epsilon = abs($float - $int);
     if (!($epsilon <= self::EPSILON || 1 - $epsilon <= self::EPSILON)) {
         $this->throwException("ValueException", "The data is not a multiple of the value (epsilon = {$epsilon})", $data);
     }
 }