/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/Validation
NameSizeModeActions
composer.json10270644editdlrm
LICENSE.txt12040644editdlrm
README.md12170644editdlrm
RulesProvider.php25440644editdlrm
ValidatableInterface.php11310644editdlrm
Validation.php617860644editdlrm
ValidationRule.php64880644editdlrm
ValidationSet.php56590644editdlrm
Validator.php1036080644editdlrm
ValidatorAwareInterface.php17310644editdlrm
ValidatorAwareTrait.php69630644editdlrm
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/Validation/ValidationRule.php (6488B)
$validator [optional] The validator properties */ public function __construct(array $validator = []) { $this->_addValidatorProps($validator); } /** * Returns whether this rule should break validation process for associated field * after it fails * * @return bool */ public function isLast(): bool { return $this->_last; } /** * Dispatches the validation rule to the given validator method and returns * a boolean indicating whether the rule passed or not. If a string is returned * it is assumed that the rule failed and the error message was given as a result. * * @param mixed $value The data to validate * @param array $providers Associative array with objects or class names that will * be passed as the last argument for the validation method * @param array $context A key value list of data that could be used as context * during validation. Recognized keys are: * - newRecord: (boolean) whether the data to be validated belongs to a * new record * - data: The full data that was passed to the validation process * - field: The name of the field that is being processed * @return array|string|bool * @throws \InvalidArgumentException when the supplied rule is not a valid * callable for the configured scope */ public function process($value, array $providers, array $context = []) { $context += ['data' => [], 'newRecord' => true, 'providers' => $providers]; if ($this->_skip($context)) { return true; } if (!is_string($this->_rule) && is_callable($this->_rule)) { $callable = $this->_rule; $isCallable = true; } else { $provider = $providers[$this->_provider]; $callable = [$provider, $this->_rule]; $isCallable = is_callable($callable); } if (!$isCallable) { /** @psalm-suppress PossiblyInvalidArgument */ $message = sprintf( 'Unable to call method "%s" in "%s" provider for field "%s"', $this->_rule, $this->_provider, $context['field'] ); throw new InvalidArgumentException($message); } if ($this->_pass) { $args = array_values(array_merge([$value], $this->_pass, [$context])); $result = $callable(...$args); } else { $result = $callable($value, $context); } if ($result === false) { return $this->_message ?: false; } return $result; } /** * Checks if the validation rule should be skipped * * @param array $context A key value list of data that could be used as context * during validation. Recognized keys are: * - newRecord: (boolean) whether the data to be validated belongs to a * new record * - data: The full data that was passed to the validation process * - providers associative array with objects or class names that will * be passed as the last argument for the validation method * @return bool True if the ValidationRule should be skipped */ protected function _skip(array $context): bool { if (!is_string($this->_on) && is_callable($this->_on)) { $function = $this->_on; return !$function($context); } $newRecord = $context['newRecord']; if (!empty($this->_on)) { return ($this->_on === Validator::WHEN_CREATE && !$newRecord) || ($this->_on === Validator::WHEN_UPDATE && $newRecord); } return false; } /** * Sets the rule properties from the rule entry in validate * * @param array $validator [optional] * @return void */ protected function _addValidatorProps(array $validator = []): void { foreach ($validator as $key => $value) { if (empty($value)) { continue; } if ($key === 'rule' && is_array($value) && !is_callable($value)) { $this->_pass = array_slice($value, 1); $value = array_shift($value); } if (in_array($key, ['rule', 'on', 'message', 'last', 'provider', 'pass'], true)) { $this->{"_$key"} = $value; } } } /** * Returns the value of a property by name * * @param string $property The name of the property to retrieve. * @return mixed */ public function get(string $property) { $property = '_' . $property; return $this->{$property} ?? null; } }