String validator.

@param mixed $data Data to validate
@param callable $filter Custom filter
@return bool
17590
public static function validateString($data, callable $filter=null) {
        if ( is_string($data) === false ) return false;
        return self::applyFilter($data, $filter);
    }
1113854
private static function determineTokenType($filter)
	{
		if (in_array(substr($filter, 0, 2), array_keys(self::$supported_tokens))) {
			// Two character token (<=, >=, etc)
			return substr($filter, 0, 2);
		} elseif (in_array($filter[0], array_keys(self::$supported_tokens))) {
			// Single character token (>, ^, $)
			return $filter[0];
		}

		// No token
		return false;
	}
286548
protected static function parseParameterFilter($filter)
	{
		list($name, $parameters) = explode(':', $filter, 2);

		return array($name, explode(',', $parameters));
	}
968935
public function validator($entity, $data)
    {
        return ValidationManager::validator(self::getInstance()->getEntityStructure($entity), $data);
    }
943628
public function validation($data, $files) {

        $errors = array();

        if (array_key_exists('plugin', $this->_customdata) && is_object($this->_customdata['plugin'])) {
            $pluginerrors = $this->_customdata['plugin']->export_config_validation($data);
            if (is_array($pluginerrors)) {
                $errors = $pluginerrors;
            }
        }
        if (array_key_exists('caller', $this->_customdata) && is_object($this->_customdata['caller'])) {
            $callererrors = $this->_customdata['caller']->export_config_validation($data);
            if (is_array($callererrors)) {
                $errors = array_merge($errors, $callererrors);
            }
        }
        return $errors;
    }
1120623
public function check($data)
    {
        $this->validAttribs   = array();
        $this->invalidAttribs = array();
        $this->missingAttribs = array();
        $this->unknownAttribs = array();
        $requiredDependent    = array();
        $seenAttrib           = array();

        foreach (U::flatten($data) as $attribName => $value) {
            $attrib = $this->dataFilter->getAttrib($attribName);
            if (!$attrib) {
                $parts = explode(U::$FLATTEN_SEPARATOR, $attribName);
                $count = count($parts);
                if ($count > 1) {

                    for ($i = $count -1; $i >= 1; $i--) {
                        $testName = join(U::$FLATTEN_SEPARATOR, array_splice($parts, 0, $i));
                        $attrib   = $this->dataFilter->getAttrib($testName. U::$FLATTEN_SEPARATOR. '*');
                        if ($attrib) {
                            break 1;
                        }
                    }
                }
            }
            $seenAttrib[$attribName] = true;

            // unknown attrib
            if (!$attrib) {
                $this->unknownAttribs[$attribName] = $this->dataFilter->applyFilter('pre', $value);
                continue;
            }

            // run pre-filters
            if ($attrib->useFilters()) {
                $value = $this->dataFilter->applyFilter('pre', $attrib->applyFilter('pre', $value));
            }

            // successfull check
            if ($attrib->check($value)) {
                $this->validAttribs[$attribName] = array(
                    'value'  => $attrib->useFilters()
                        ? $this->dataFilter->applyFilter('post', $attrib->applyFilter('post', $value))
                        : $value,
                    'attrib' => &$attrib
                );

                // determine possible dependents
                $attrib->determineDependents($value, $requiredDependent);
            }

            // checks failed
            else {
                $this->invalidAttribs[$attribName] = array(
                    'value'  => $value,
                    'attrib' => &$attrib,
                    'error'  => $attrib->getError()
                );
            }
        }

        // check now all attribs for required
        foreach ($this->dataFilter->getAttribs() as $attribName => $attrib) {

            // already seen
            if (isset($seenAttrib[$attribName])) {
                continue;
            }

            // has default
            elseif (!is_null($default = $attrib->getDefault())) {
                $this->validAttribs[$attribName] = ['value' => $default, 'attrib' => &$attrib];
            }

            // required -> missing
            elseif ($attrib->isRequired() || isset($requiredDependent[$attribName])) {
                $parts = explode(U::$FLATTEN_SEPARATOR, $attribName);
                $count = count($parts);
                if ($count > 1 && $parts[$count-1] === '*') {
                    $before = join(U::$FLATTEN_SEPARATOR, array_splice($parts, 0, $count - 1)). U::$FLATTEN_SEPARATOR;
                    $seen   = array_filter(array_keys($seenAttrib), function ($check) use ($before) {
                        return strpos($check, $before) === 0;
                    });
                    if (count($seen) > 0) {
                        continue;
                    }
                }
                $this->missingAttribs[$attribName] = array(
                    'attrib' => &$attrib,
                    'error'  => $attrib->getMissingText()
                );
            }
        }

        /*error_log("INVALID: ". count($this->invalidAttribs));
        error_log("MISSING: ". count($this->missingAttribs));*/
        return !$this->hasError();
    }
217333
public function validate($data, $throwException = true)
    {
        if (empty($rules = $this->getRules())) {
            return true;
        } else {
            $validator = Validator::make($data, $rules, $this->validationMessages);

            if ($validator->fails()) {
                $this->errors($validator->errors()->getMessages());
                if ($throwException) {
                    $errorString = DataFormatter::validationErrorsToString($this->getErrors());
                    throw new BadRequestException('Invalid data supplied.' . $errorString, null, null, $this->getErrors());
                } else {
                    return false;
                }
            } else {
                return true;
            }
        }
    }
389254
public function validate($data, $type) {
        if (strtolower($type) == "create") $rules = $this->repository->getValidationRulesForCreate();

        if (strtolower($type) == "update") $rules = $this->repository->getValidationRulesForUpdate();

        $validator = Validator::make($data,$rules);

        if ($validator->fails()) return $validator->messages();

        return "passed";
    }
32492
protected function beforeValidation($data)
  {
    if ($this->before_validation) {
      $data = call_user_func_array($this->before_validation, array($data, $this));
    }

    return $data;
  }
852864
protected function convertToArray($data, $filter = 'raw')
    {
        $array = [];

        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $array[$key] = $this->convertToArray($value);
            } else {
                $array[$key] = $this->filter->clean($value, $filter);
            }
        }

        return $array;
    }
497317
public static function fromArray(array $data, $filter = false){
        $class = get_called_class();
        $object = new static();
        foreach($data as $key => $value){
            if(!$filter || property_exists($class, $key)){
                $object->$key = $value;
            }
        }
        return $object;
    }
644005
protected function convertToFilterFormat($filter)
    {
        $filter = trim($filter);
        if (substr($filter, 0, 1) != '(') {
            $filter = '(' . $filter;
        }
        if (substr($filter, -1) != ')') {
            $filter = $filter . ')';
        }
        return $filter;
    }
792511
public static function validateFloat($data, callable $filter=null) {
        if ( is_float($data) === false ) return false;
        return self::applyFilter($data, $filter);
    }
1252906
def get_validator(filter_data):
    
    for matcher_type, m in matchers.items():
        if hasattr(m, 'can_handle') and m.can_handle(filter_data):
            filter_data = m.handle(filter_data)

    return filter_data
51392
protected function handle($item, callable $filter = null)
    {
        if (null !== $filter) {
            return call_user_func($filter, $item);
        }
        return $item;
    }
747767
protected function createFilter($filter)
    {
        if (is_callable($filter)) {
            return call_user_func($filter);
        } elseif (is_string($filter)) {
            return new $filter();
        } elseif (is_object($filter)) {
            return $filter;
        } else {
            throw new \InvalidArgumentException("Cannot convert $filter to filter");
        }
    }
1247805
public static function validate($data, $type, callable $filter=null) {

        $type = strtoupper($type);

        if ( !array_key_exists($type, self::$supported_types) ) {
            throw new UnexpectedValueException("Bad validation type");
        }

        return call_user_func(self::$supported_types[$type], $data, $filter);

    }