Esempio n. 1
0
 /**
  * Validates the parameters value and returns the result.
  * @see ParamDefinition::validateValue
  *
  * @since 0.5
  *
  * @param $value mixed
  * @param $param IParam
  * @param $definitions array of IParamDefinition
  * @param $params array of IParam
  * @param ValidatorOptions $options
  *
  * @return boolean
  */
 protected function validateValue($value, IParam $param, array $definitions, array $params, ValidatorOptions $options)
 {
     if ($options->isStringlyTyped()) {
         if (!is_string($value)) {
             return false;
         }
         $isNegative = false;
         if ($this->allowNegatives && strpos($value, '-') === 0) {
             $value = substr($value, 1);
             $isNegative = true;
         }
         if (ctype_digit((string) $value)) {
             $value = (int) $value;
             if ($isNegative) {
                 $value = -$value;
             }
         } else {
             return false;
         }
     } elseif (!is_int($value) && !is_float($value) || !$this->allowNegatives && $value < 0) {
         return false;
     }
     if (is_float($value)) {
         if ((int) $value == $value) {
             $value = (int) $value;
         } else {
             return false;
         }
     }
     return parent::validateValue($value, $param, $definitions, $params, $options);
 }
Esempio n. 2
0
 /**
  * Validates the parameters value and returns the result.
  * @see ParamDefinition::validateValue
  *
  * @since 0.5
  *
  * @param $value mixed
  * @param $param IParam
  * @param $definitions array of IParamDefinition
  * @param $params array of IParam
  * @param ValidatorOptions $options
  *
  * @return boolean
  */
 protected function validateValue($value, IParam $param, array $definitions, array $params, ValidatorOptions $options)
 {
     if ($options->isStringlyTyped()) {
         if (preg_match('/^(-)?\\d+((\\.|,)\\d+)?$/', $value)) {
             $value = (double) $value;
         } else {
             return false;
         }
     } elseif (!is_float($value) && !is_int($value)) {
         return false;
     }
     return parent::validateValue($value, $param, $definitions, $params, $options);
 }
Esempio n. 3
0
 /**
  * @since 0.5
  *
  * @param mixed $value
  * @param IParam $param
  * @param $definitions array of IParamDefinition
  * @param $params array of IParam
  * @param ValidatorOptions $options
  *
  * @return boolean
  */
 protected final function validateValueBase($value, IParam $param, array $definitions, array $params, ValidatorOptions $options)
 {
     if ($options->isStringlyTyped() && !is_string($value)) {
         return false;
     }
     return $this->validateValue($value, $param, $definitions, $params, $options);
 }