/** * @return string */ public function filter($raw, DictionaryInterface $params) { $this->clearFailure(); $default = $params->get('default', null); $options = array('options' => array()); if (null !== $default) { $options['options']['default'] = $default; } $decimal = $params->get('decimal-sep', false); if (is_string($decimal) && !empty($decimal)) { $options['options']['decimal'] = $decimal; } /* * allow the use of thousand marker */ if ($params->get('allow-thousands', false)) { $options['flags'] = FILTER_FLAG_ALLOW_THOUSAND; } /* will bitwise or the flag if it exists */ if ($params->get('allow-fractions', false)) { if (!isset($options['flag'])) { $options['flags'] = FILTER_FLAG_ALLOW_FRACTION; } else { $options['flag'] |= FILTER_FLAG_ALLOW_FRACTION; } } $result = filter_var($raw, FILTER_VALIDATE_FLOAT, $options); if (false === $result) { $this->enableFailure(); return null; } return $result; }
/** * @param mixed $raw input to filter * @param DictionaryInteface $params used to control filtering * @return mixed | failedFilterToken */ public function filter($raw, DictionaryInterface $params) { $this->clearFailure(); $default = $params->get('default', null); $options = array('options' => array()); if (null !== $default) { $options['options']['default'] = $default; } $result = filter_var($raw, FILTER_VALIDATE_EMAIL, $options); if (!$result) { $this->enableFailure(); return null; } return $result; }
/** * @param mixed $raw input to filter * @param DictionaryInteface $params used to control filtering * @return mixed | failedFilterToken */ public function filter($raw, DictionaryInterface $params) { $this->clearFailure(); $default = $params->get('default', null); $options = array('options' => array()); if (null !== $default) { $options['options']['default'] = $default; } if ($params->get('strict', false)) { $options['flags'] = FILTER_NULL_ON_FAILURE; } $result = filter_var($raw, FILTER_VALIDATE_BOOLEAN, $options); if (null === $result) { $this->enableFailure(); return null; } return $result; }
/** * @return string */ public function filter($raw, DictionaryInterface $params) { $this->clearFailure(); $default = $params->get('default', null); $options = array('options' => array()); if (null !== $default) { $options['options']['default'] = $default; } $min = $params->get('min', null); if (null !== $min) { $options['options']['min_range'] = $min; } $max = $params->get('max', null); if (null !== $max) { $options['options']['max_range'] = $max; } if ($params->get('allow-octal', false)) { $options['flags'] = FILTER_FLAG_ALLOW_OCTAL; } else { if ($params->get('allow-hex', false)) { $options['flags'] = FILTER_FLAG_ALLOW_HEX; } } $result = filter_var($raw, FILTER_VALIDATE_INT, $options); if (false === $result) { $this->enableFailure(); return null; } return $result; }
/** * @param mixed $raw input to filter * @param DictionaryInteface $params used to control filtering * @return mixed | failedFilterToken */ public function filter($raw, DictionaryInterface $params) { $this->clearFailure(); $default = $params->get('default', null); $options = array('options' => array()); if (null !== $default) { $options['options']['default'] = $default; } if ($params->get('ipv4', false)) { $options['flags'] = FILTER_FLAG_IPV4; } if ($params->get('ipv6', false)) { $options['flags'] = FILTER_FLAG_IPV6; } if ($params->get('no-private-ranges', false)) { $options['flags'] = FILTER_FLAG_NO_PRIV_RANGE; } if ($params->get('no-reserved-ranges', false)) { $options['flags'] = FILTER_FLAG_NO_RES_RANGE; } $result = filter_var($raw, FILTER_VALIDATE_IP, $options); if (!$result) { $this->enableFailure(); return null; } return $result; }
/** * @param DictionaryInterface $error * @return QueryResult */ protected function setErrorDictionary(DictionaryInterface $error) { $this->error = $error->getAll(); return $this; }