Validates a single value with the given rules.

@param mixed       $value
@param AllOf|array $rules
@param string      $key
@param string|null $group
@param string[]    $messages

@return self
779103
public function value($value, $rules, string $key, string $group = null, array $messages = []): self
    {
        return $this->validateInput($value, new Configuration($rules, $key, $group), $messages);
    }
954637
public function validate($rules = [], $errors = [])
    {
        foreach ($rules as $param => $subRules) {
            $paramValue = $this->getParam($param);
            foreach ($subRules as $key => $rule) {
                $isError = false;
                if (!is_array($rule)) {
                    switch ($rule) {
                        case self::VALIDATE_REQUIRED:
                            if (is_null($paramValue)) {
                                $isError = true;
                            }
                            break;
                        case self::VALIDATE_MOBILE:
                            if (!ValidationHelper::isMobile($paramValue)) {
                                $isError = true;
                            }
                            break;
                    }
                } else {
                    switch ($key) {
                    case self::VALIDATE_ENUM:
                        if (!in_array($paramValue, $rule)) {
                            $isError = true;
                        }
                        break;
                    }
                }
                if ($isError) {
                    $errCode = self::ERROR_INVALID_PARAM;
                    $errMsg = self::errorMsg[self::ERROR_INVALID_PARAM];
                    if (is_array($rule)) {
                        $rule = $key;
                    }
                    if (isset($errors[$param][$rule]['code'])) {
                        $errCode = $errors[$param][$rule]['code'];
                    }
                    if (isset($errors[$param][$rule]['msg'])) {
                        $errMsg = str_replace('{param}', $param, $errors[$param][$rule]['msg']);
                    }
                    throw new ParamException($errMsg, $errCode);
                }
            }
        }
    }
562256
public function regex($key, $pattern, $message = null)
    {
        if (is_array($key)) {
            foreach ($key as $k => $name) {
                $this->regex($name, is_array($pattern) ? $pattern[$k] : $pattern, $message);
            }
        } else {
            if (isset($this->scope[$key]) && ! (bool)preg_match($pattern, $this->scope[$key])) {
                $this->errors[$key] = sprintf($message !== null ? $message : self::$regexMessage, $key);
            }
        }

        return $this;
    }
885942
public function validateWithBag(
        $errorBag,
        Request $request,
        array $rules,
        array $messages = [],
        array $attributes = []
    ) {
        try {
            return $this->validate($request, $rules, $messages, $attributes);
        } catch (ValidationException $e) {
            $e->errorBag = $errorBag;
            throw $e;
        }
    }
343422
public function hasError($key, $group = null)
    {
        return !empty($this->validator->getErrors($key, $group));
    }
61645
protected function makeValidationRuleDataFromSpecialArraySyntax(array $rules, $key)
    {
        $data = new ValidationRuleData(
            array_get($rules, 'rules', []),
            array_get($rules, 'key', is_numeric($key) ? null : $key)
        );

        if (array_has($rules, 'translated')) {
            $data->setIsTranslated((bool) $rules['translated']);
        }

        if (array_has($rules, 'locale_index')) {

            // @codeCoverageIgnoreStart
            if ((int) $rules['locale_index'] < 1) {
                throw new UnexpectedValueException(
                    "Locale index for configured validation data cannot be less than 1 (key/index: {$key})"
                );
            }
            // @codeCoverageIgnoreEnd

            $data->setLocaleIndex((int) $rules['locale_index']);
        }

        return $data;
    }
200611
public function rule_max( $key, $value, $max )
	{
		return $this->rule_max_num( $key, strlen( $value ), $max );
	}
462958
private function validateInput($input, $rules, $key)
    {
        if (isset($input[$key]) && isset($rules[$key])) {
            $ruleExp = explode('|', $rules[$key]);

            foreach ($ruleExp as $rule) {
                $this->parseRule($rule, $input, $key);
            }
        }
    }
750688
protected function getErrors($value, $constraints = null, $groups = null)
    {
        /** @var ValidatorInterface $validator */
        $validator = $this->getContainer()->get(Config::getServiceName());

        return $validator->validate($value, $constraints, $groups);
    }
575968
public function validate(array $values, array $rules)
    {
        // Assume no validation and result success
        $result = true;

        if (true !== $valid = $this->validateByRules($rules, $values)) {
            foreach ($valid as $componentName => $error) {
                $this->setError($error, $componentName);
            }

            // Set general form error
            $this->setError(
                [
                    'error' => 'general',
                    'info'  => [],
                ],
                Doozr_Form_Service_Constant::ERROR_IDENTIFIER_FORM
            );

            $result = false;
        }

        return $result;
    }
1354273
protected function buildCondition(ConditionGroupContract $group, $key, $value)
    {

        if (is_array($value)) {
            return $group->where($key, 'in', $value);
        }

        if (is_numeric($value)) {
            return $group->where($key, '=', $value);
        }

        if (Type::isStringLike($value)) {
            return $group->where($key, 'like', "$value");
        }

        return $group->where($key, $value);

    }
330576
protected function validate_by_key( $values ) {

		$is_valid = TRUE;

		if ( count( $this->validators_by_key ) < 1 ) {

			return $is_valid;
		}

		foreach ( $values as $key => $value ) {
			if ( ! is_scalar( $value ) || ! isset( $this->validators_by_key[ $key ] ) ) {
				continue;
			}

			/** @var $validators ValidatorInterface[] */
			$validators = $this->validators_by_key[ $key ];
			foreach ( $validators as $validator ) {
				$is_valid = $validator->is_valid( $value );

				if ( ! $is_valid ) {
					$this->error_messages[ $key ] = $validator->get_error_messages();
					break;
				}
			}

			if ( ! $is_valid ) {
				break;
			}
		}

		return $is_valid;
	}
1241598
public function create($key, $value, $group = Manager::DEFAULT_GROUP)
    {
        return $this->createModel()->create([
            'key' => $key,
            'value' => $value,
            'group' => $group,
        ]);
    }
1126845
public function isValid($key, $value)
    {
        $settings = collect(
            $this->getRegistered()->get($key, ['allowed' => []])
        );

        $allowed = $settings->get('allowed');

        if (!is_array($allowed) &&
            $rule = $this->ruleValidator->isRule($allowed)) {
            return $this->ruleValidator->validate($rule, $value);
        }

        return in_array($value, $allowed, true);
    }
508421
public function validateData(array $data, array $rules, array $messages)
    {
        if ($rules) {
            $this->customValidator->setData($data);
            $this->customValidator->setRules($rules);
            $this->customValidator->setCustomMessages($messages);

            //if the validator fails, kick back the errors
            if ($this->customValidator->fails()) {
                return implode('. ', $this->customValidator->messages()->all());
            }
        }

        return true;
    }
920279
public function isValidValue($rules, $value) {
        $result = [];
        foreach ($rules as $rule) {
            $parameters = $rule;
            $name       = array_shift($parameters);
            $valid      = $this->isValidRule($name, $parameters, $value);
            if ($valid !== null) {
                $result[] = $valid;
            }
        }
        return $result;
    }
1007945
public function setErrors(array $errors, string $key = null, string $group = null): self
    {
        if (!empty($group)) {
            if (!empty($key)) {
                $this->errors[$group][$key] = $errors;
            } else {
                $this->errors[$group] = $errors;
            }
        } elseif (!empty($key)) {
            $this->errors[$key] = $errors;
        } else {
            $this->errors = $errors;
        }

        return $this;
    }