Perform a recursive action

@param  string $method
@param  array  $data
@param  array  $rules
@param  array  $messages
@return bool
3276
private function recurse($method, array $data = [], array $rules = [], array $messages = [])
    {
        // Make sure method is valid
        if ( ! in_array($method, ['save', 'validate'])) return false;

        // Disable validation
        $validateBeforeSave = $this->validateBeforeSave;
        $this->validateBeforeSave = false;

        // Perform action
        $result = $this->{$method}($data, $rules, $messages);

        // Check for relationships
        $relationships = $this->getRelationships();

        // Recurse into each relationship if we can
        foreach ($relationships as $name => $type)
        {
            $subresult = $this->recurseRelationship($method, $name, $type);

            // If a relationship fails, we fail
            if ( ! $subresult) $result = false;
        }

        // Reset validation
        $this->validateBeforeSave = $validateBeforeSave;

        return $result;
    }
814350
public function setRule($rule, $function, $message = '', $args = array())
    {
        if (!array_key_exists($rule, $this->rules)) {
            $this->rules[$rule] = TRUE;
            if (!array_key_exists($rule, $this->functions)) {
                if (!is_callable($function)) {
                    die('Invalid function for rule: ' . $rule);
                }
                $this->functions[$rule] = $function;
            }
            $this->arguments[$rule] = $args; // Specific arguments for rule

            $this->messages[$rule] = (empty($message)) ? $this->_getDefaultMessage($rule, $args) : $message;
        }
    }
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;
    }
840382
protected function runRegex($regex, $key, $datas, $rule)
    {
        if (!preg_match($regex, $datas[$key])) {
            $this->fails[] = $messageKey = "regex.$key";

            $this->addMessage($key, $rule, $messageKey);
        }
    }
519148
protected function _process($action, Data $messages, array $redirect, array $ids)
    {
        $count = count($ids);
        $defaultMsg = __dn(
            'core',
            'One record success processed',
            '{0} records processed',
            $count,
            sprintf('<strong>%s</strong>', $count)
        );

        EventManager::trigger($this->_getEventName($action, self::EVENT_NAME_AFTER), $this->_controller, [
            'ids' => $ids
        ]);

        $this->Flash->success($messages->get($action, $defaultMsg));
        return $this->_controller->redirect($redirect);
    }
940794
private function validateData($rules, $data) {
		$errors = [];
		foreach ($rules as $field => $rule) {
			$valid = $this->validateField($field, $data, $rule);
			if ($valid !== true) {
				$errors[ $field ] = $valid;
			}
		}
		if (!empty($errors)) {
			throw new ValidateException($errors);
		}

		return true;
	}
49525
public function send($uri, $method, array $headers = [], $datas = [], array $files = [])
    {
        return $this->sendRequest($this->getConfiguration()->getMessageFactory()->createInternalRequest(
            $uri,
            $method,
            $this->getConfiguration()->getProtocolVersion(),
            $headers,
            $datas,
            $files
        ));
    }
1091187
public function validate(array $data, $rules = null, $custom = false)
    {
        if (!$custom) {
            $rules = $this->rules($rules);
        }

        return $this->validator->make($data, $rules);
    }
903118
private function handleRule($rule, $key, array $allDatas)
    {

        $methodName = "run";

        if (!strstr($rule, "_")) {
            $methodName .= ucfirst($rule);
        } else {
            $parsedName = array_map(function ($value) {
                return ucfirst($value);
            }, explode("_", $rule));

            $methodName = $methodName . join("", $parsedName);
        }

        if (!strstr($rule, ":")) {
            $called = $this->callMethod($methodName, [$key, $allDatas, $rule]);
        } else {
            $value = explode(":", $key)[1];
            if (strstr($value, ",")) {
                $sendDatas = [explode(",", $value), $key, $allDatas, $rule];
            } else {
                $sendDatas = [$value, $key, $allDatas, $rule];
            }

            $called = $this->callMethod($methodName, $sendDatas);
        }

        return $called;

    }
699183
public function validate(array $data = [], array $rules = [], array $messages = [])
    {
        $this->prepareRecord($data, $rules, $messages);

        return $this->validateRecord();
    }
598269
public function applyRules(array $rules = [], array $data = []): array
    {
        $data  = $data ?: $this->_data;
        $rules = $rules ?: $this->_rules;
        // save clean data
        $filtered = [];

        foreach ($rules as $rule) {
            if (!isset($rule[0], $rule[1])) {
                continue;
            }

            if (!$fields = $rule[0]) {
                continue;
            }

            $fields = \is_string($fields) ? Filters::explode($fields) : (array)$fields;

            foreach ($fields as $field) {
                if (!isset($data[$field])) {
                    $filtered[$field] = $rule['default'] ?? null;
                } else {
                    $filtered[$field] = $this->valueFiltering($data[$field], $rule[1]);
                }
            }
        }

        return $filtered;
    }
483563
public function method(string $method, string ...$methods): self
    {
        array_unshift($methods, $method);

        return $this->setAllowedMethods($methods);
    }
544223
protected function createValidator(array $data, array $rules)
    {
        /** @var Factory $factory */
        $factory   = app('validator');
        $validator = $factory->make($data, $rules);

        return $validator;
    }
1299776
protected function runNumeric($key, $datas, $rule = '')
    {

        if (!isset($datas[$key])) {
            if (!is_numeric($datas[$key])) {
                $this->fails[] = $messageKey = "numeric.$key";

                $this->addMessage($key, $rule, $messageKey);
            }
        }
    }
199138
public static function make(array $data, array $rules, array $userMessages = [])
    {
        self::$validatorFacade = new ValidatorFacade($userMessages);

        $data = self::prepareData($data);
        $rules = self::prepareRules($rules);

        foreach ($rules as $fieldName => $fieldRules) {
            $fieldName = trim($fieldName);
            $fieldRules = trim($fieldRules);

            if (!$fieldRules) {
                //no rules
                continue;
            }

            $groupedRules = explode('|', $fieldRules);

            foreach ($groupedRules as $concreteRule) {
                $ruleNameParam = explode(':', $concreteRule);
                $ruleName = $ruleNameParam[0];

                //for date/time validators
                if (count($ruleNameParam) >= 2) {
                    $ruleValue = implode(':', array_slice($ruleNameParam, 1));

                    //for other params
                } else {
                    $ruleValue = isset($ruleNameParam[1]) ? $ruleNameParam[1] : '';
                }

                self::$config[BaseRule::CONFIG_DATA] = $data;
                self::$config[BaseRule::CONFIG_FIELD_RULES] = $fieldRules;

                $ruleInstance = RulesFactory::createRule($ruleName, self::$config, [
                    $fieldName,                                        // The field name
                    isset($data[$fieldName]) ? $data[$fieldName] : '', // The provided value
                    $ruleValue,                                        // The rule's value
                ]);

                if (!$ruleInstance->isValid()) {
                    self::$validatorFacade->chooseErrorMessage($ruleInstance);
                }
            }
        }

        return self::$validatorFacade;
    }
184554
protected function addMessage($key, $rule, $specialRule, array $datas = [])
    {
        $specialMessages = $this->getMessageReposity();
        $defaultMessages = $this->defaultErrorMessages;

        if (count($datas) === 0) {
            $datas = [$key];
        }

        if (isset($specialMessages[$specialRule])) {
            $selectedMessage = $specialMessages[$specialRule];
        } else {
            $selectedMessage = $defaultMessages[$rule];
        }

        array_unshift($datas, $selectedMessage);
        $this->failedMessages[] = call_user_func_array('sprintf', $datas);
    }
628408
public static function make($data, array $rules, array $customMessages = [], array $attributes = [])
    {
        return new Validator($data, $rules, $customMessages, $attributes);
    }