Example #1
0
 /**
  * This function validates the specified value against any constraints.
  *
  * @access protected
  * @override
  * @param mixed $value                          the value to be validated
  * @return boolean                              whether the specified value validates
  */
 protected function validate($value)
 {
     if ($value !== NULL) {
         if ($this->metadata['unsigned'] and $value < 0.0) {
             return FALSE;
         } else {
             if (isset($this->metadata['range'])) {
                 if ($value < $this->metadata['range']['lower_bound'] or $value > $this->metadata['range']['upper_bound']) {
                     return FALSE;
                 }
             }
         }
         if (isset($this->metadata['max_digits'])) {
             $parts = preg_split('/\\./', "{$value}");
             $digits = strlen("{$parts[0]}");
             if (isset($this->metadata['max_decimals']) and count($parts) > 1) {
                 $decimals = strlen("{$parts[1]}");
                 if ($decimals > $this->metadata['max_decimals']) {
                     return FALSE;
                 }
                 $digits += $decimals;
             }
             if ($digits > $this->metadata['max_digits']) {
                 return FALSE;
             }
         }
     }
     return parent::validate($value);
 }
Example #2
0
 /**
  * This function validates the specified value against any constraints.
  *
  * @access protected
  * @override
  * @param mixed $value                          the value to be validated
  * @return boolean                              whether the specified value validates
  */
 protected function validate($value)
 {
     if ($value !== NULL) {
         if (strlen($value) > $this->metadata['max_length']) {
             return FALSE;
         } else {
             if (isset($this->metadata['regex']) and !preg_match($this->metadata['regex'], $value)) {
                 return FALSE;
             }
         }
     }
     return parent::validate($value);
 }
Example #3
0
 /**
  * This function validates the specified value against any constraints.
  *
  * @access protected
  * @override
  * @param mixed $value                          the value to be validated
  * @return boolean                              whether the specified value validates
  */
 protected function validate($value)
 {
     if ($value !== NULL) {
         if (strlen("{$value}") > $this->metadata['precision']) {
             return FALSE;
         }
     }
     return parent::validate($value);
 }
Example #4
0
 /**
  * This function validates the specified value against any constraints.
  *
  * @access protected
  * @override
  * @param mixed $value                          the value to be validated
  * @return boolean                              whether the specified value validates
  */
 protected function validate($value)
 {
     if ($value !== NULL) {
         if (!$value instanceof $this->metadata['type']) {
             return FALSE;
         }
         if (!$value->has_pattern($this->metadata['pattern'])) {
             return FALSE;
         }
     }
     return parent::validate($value);
 }
Example #5
0
 /**
  * This function validates the specified value against any constraints.
  *
  * @access protected
  * @override
  * @param mixed $value                          the value to be validated
  * @return boolean                              whether the specified value validates
  */
 protected function validate($value)
 {
     if ($value !== NULL) {
         if (strlen($value) > $this->metadata['max_length'] and !preg_match('/^(0|1)*$/', $value)) {
             return FALSE;
         }
     }
     return parent::validate($value);
 }
Example #6
0
 /**
  * This function validates the specified value against any constraints.
  *
  * @access protected
  * @override
  * @param mixed $value                          the value to be validated
  * @return boolean                              whether the specified value validates
  */
 protected function validate($value)
 {
     if ($value !== NULL) {
         if (isset($this->metadata['max_length']) and strlen(strval($value)) > $this->metadata['max_length']) {
             return FALSE;
         }
         if (isset($this->metadata['int8fix'])) {
             if (!preg_match('/^-?[0-9]+$/D', strval($value)) or bccomp(strval($value), strval($this->metadata['range']['lower_bound'])) === -1 or bccomp(strval($value), strval($this->metadata['range']['upper_bound'])) === 1) {
                 return FALSE;
             }
         } else {
             if ($value < $this->metadata['range']['lower_bound'] or $value > $this->metadata['range']['upper_bound']) {
                 return FALSE;
             }
         }
     }
     return parent::validate($value);
 }