code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
protected function explodeWildcardRules($results, $attribute, $rules)
{
$pattern = str_replace('\*', '[^\.]*', preg_quote($attribute, '/'));
$data = ValidationData::initializeAndGatherData($attribute, $this->data);
foreach ($data as $key => $value) {
if (Str::startsWith($key, $attribute) || (bool) preg_match('/^'.$pattern.'\z/', $key)) {
foreach ((array) $rules as $rule) {
if ($rule instanceof CompilableRules) {
$context = Arr::get($this->data, Str::beforeLast($key, '.'));
$compiled = $rule->compile($key, $value, $data, $context);
$this->implicitAttributes = array_merge_recursive(
$compiled->implicitAttributes,
$this->implicitAttributes,
[$attribute => [$key]]
);
$results = $this->mergeRules($results, $compiled->rules);
} else {
$this->implicitAttributes[$attribute][] = $key;
$results = $this->mergeRules($results, $key, $rule);
}
}
}
}
return $results;
} | Define a set of rules that apply to each element in an array attribute.
@param array $results
@param string $attribute
@param string|array $rules
@return array | explodeWildcardRules | php | laravel/framework | src/Illuminate/Validation/ValidationRuleParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidationRuleParser.php | MIT |
protected function mergeRulesForAttribute($results, $attribute, $rules)
{
$merge = head($this->explodeRules([$rules]));
$results[$attribute] = array_merge(
isset($results[$attribute]) ? $this->explodeExplicitRule($results[$attribute], $attribute) : [], $merge
);
return $results;
} | Merge additional rules into a given attribute.
@param array $results
@param string $attribute
@param string|array $rules
@return array | mergeRulesForAttribute | php | laravel/framework | src/Illuminate/Validation/ValidationRuleParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidationRuleParser.php | MIT |
public static function parse($rule)
{
if ($rule instanceof RuleContract || $rule instanceof CompilableRules) {
return [$rule, []];
}
if (is_array($rule)) {
$rule = static::parseArrayRule($rule);
} else {
$rule = static::parseStringRule($rule);
}
$rule[0] = static::normalizeRule($rule[0]);
return $rule;
} | Extract the rule name and parameters from a rule.
@param array|string $rule
@return array | parse | php | laravel/framework | src/Illuminate/Validation/ValidationRuleParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidationRuleParser.php | MIT |
protected static function ruleIsRegex($rule)
{
return in_array(strtolower($rule), ['regex', 'not_regex', 'notregex'], true);
} | Determine if the rule is a regular expression.
@param string $rule
@return bool | ruleIsRegex | php | laravel/framework | src/Illuminate/Validation/ValidationRuleParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidationRuleParser.php | MIT |
protected static function normalizeRule($rule)
{
return match ($rule) {
'Int' => 'Integer',
'Bool' => 'Boolean',
default => $rule,
};
} | Normalizes a rule so that we can accept short types.
@param string $rule
@return string | normalizeRule | php | laravel/framework | src/Illuminate/Validation/ValidationRuleParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidationRuleParser.php | MIT |
public function compile($attribute, $value, $data = null, $context = null)
{
$rules = call_user_func($this->callback, $value, $attribute, $data, $context);
return Rule::compile($attribute, $rules, $data);
} | Compile the callback into an array of rules.
@param string $attribute
@param mixed $value
@param mixed $data
@param mixed $context
@return \stdClass | compile | php | laravel/framework | src/Illuminate/Validation/NestedRules.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/NestedRules.php | MIT |
public function __construct(
Translator $translator,
array $data,
array $rules,
array $messages = [],
array $attributes = [],
) {
if (! isset(static::$placeholderHash)) {
static::$placeholderHash = Str::random();
}
$this->initialRules = $rules;
$this->translator = $translator;
$this->customMessages = $messages;
$this->data = $this->parseData($data);
$this->customAttributes = $attributes;
$this->setRules($rules);
} | Create a new Validator instance.
@param \Illuminate\Contracts\Translation\Translator $translator
@param array $data
@param array $rules
@param array $messages
@param array $attributes | __construct | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function replacePlaceholderInString(string $value)
{
return str_replace(
['__dot__'.static::$placeholderHash, '__asterisk__'.static::$placeholderHash],
['.', '*'],
$value
);
} | Replace the placeholders in the given string.
@param string $value
@return string | replacePlaceholderInString | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function replaceDotPlaceholderInParameters(array $parameters)
{
return array_map(function ($field) {
return str_replace('__dot__'.static::$placeholderHash, '.', $field);
}, $parameters);
} | Replace each field parameter dot placeholder with dot.
@param array $parameters
@return array | replaceDotPlaceholderInParameters | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function shouldBeExcluded($attribute)
{
foreach ($this->excludeAttributes as $excludeAttribute) {
if ($attribute === $excludeAttribute ||
Str::startsWith($attribute, $excludeAttribute.'.')) {
return true;
}
}
return false;
} | Determine if the attribute should be excluded.
@param string $attribute
@return bool | shouldBeExcluded | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function validate()
{
throw_if($this->fails(), $this->exception, $this);
return $this->validated();
} | Run the validator's rules against its data.
@return array
@throws \Illuminate\Validation\ValidationException | validate | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function validateWithBag(string $errorBag)
{
try {
return $this->validate();
} catch (ValidationException $e) {
$e->errorBag = $errorBag;
throw $e;
}
} | Run the validator's rules against its data.
@param string $errorBag
@return array
@throws \Illuminate\Validation\ValidationException | validateWithBag | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function validateAttribute($attribute, $rule)
{
$this->currentRule = $rule;
[$rule, $parameters] = ValidationRuleParser::parse($rule);
if ($rule === '') {
return;
}
// First we will get the correct keys for the given attribute in case the field is nested in
// an array. Then we determine if the given rule accepts other field names as parameters.
// If so, we will replace any asterisks found in the parameters with the correct keys.
if ($this->dependsOnOtherFields($rule)) {
$parameters = $this->replaceDotInParameters($parameters);
if ($keys = $this->getExplicitKeys($attribute)) {
$parameters = $this->replaceAsterisksInParameters($parameters, $keys);
}
}
$value = $this->getValue($attribute);
// If the attribute is a file, we will verify that the file upload was actually successful
// and if it wasn't we will add a failure for the attribute. Files may not successfully
// upload if they are too large based on PHP's settings so we will bail in this case.
if ($value instanceof UploadedFile && ! $value->isValid() &&
$this->hasRule($attribute, array_merge($this->fileRules, $this->implicitRules))
) {
return $this->addFailure($attribute, 'uploaded', []);
}
// If we have made it this far we will make sure the attribute is validatable and if it is
// we will call the validation method with the attribute. If a method returns false the
// attribute is invalid and we will add a failure message for this failing attribute.
$validatable = $this->isValidatable($rule, $attribute, $value);
if ($rule instanceof RuleContract) {
return $validatable
? $this->validateUsingCustomRule($attribute, $value, $rule)
: null;
}
$method = "validate{$rule}";
$this->numericRules = $this->defaultNumericRules;
if ($validatable && ! $this->$method($attribute, $value, $parameters, $this)) {
$this->addFailure($attribute, $rule, $parameters);
}
} | Validate a given attribute against a rule.
@param string $attribute
@param string $rule
@return void | validateAttribute | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function dependsOnOtherFields($rule)
{
return in_array($rule, $this->dependentRules);
} | Determine if the given rule depends on other fields.
@param string $rule
@return bool | dependsOnOtherFields | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function getExplicitKeys($attribute)
{
$pattern = str_replace('\*', '([^\.]+)', preg_quote($this->getPrimaryAttribute($attribute), '/'));
if (preg_match('/^'.$pattern.'/', $attribute, $keys)) {
array_shift($keys);
return $keys;
}
return [];
} | Get the explicit keys from an attribute flattened with dot notation.
E.g. 'foo.1.bar.spark.baz' -> [1, 'spark'] for 'foo.*.bar.*.baz'
@param string $attribute
@return array | getExplicitKeys | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function getPrimaryAttribute($attribute)
{
foreach ($this->implicitAttributes as $unparsed => $parsed) {
if (in_array($attribute, $parsed, true)) {
return $unparsed;
}
}
return $attribute;
} | Get the primary attribute name.
For example, if "name.0" is given, "name.*" will be returned.
@param string $attribute
@return string | getPrimaryAttribute | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function replaceDotInParameters(array $parameters)
{
return array_map(function ($field) {
return str_replace('\.', '__dot__'.static::$placeholderHash, $field);
}, $parameters);
} | Replace each field parameter which has an escaped dot with the dot placeholder.
@param array $parameters
@return array | replaceDotInParameters | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function isValidatable($rule, $attribute, $value)
{
if (in_array($rule, $this->excludeRules)) {
return true;
}
return $this->presentOrRuleIsImplicit($rule, $attribute, $value) &&
$this->passesOptionalCheck($attribute) &&
$this->isNotNullIfMarkedAsNullable($rule, $attribute) &&
$this->hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute);
} | Determine if the attribute is validatable.
@param object|string $rule
@param string $attribute
@param mixed $value
@return bool | isValidatable | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function presentOrRuleIsImplicit($rule, $attribute, $value)
{
if (is_string($value) && trim($value) === '') {
return $this->isImplicit($rule);
}
return $this->validatePresent($attribute, $value) ||
$this->isImplicit($rule);
} | Determine if the field is present, or the rule implies required.
@param object|string $rule
@param string $attribute
@param mixed $value
@return bool | presentOrRuleIsImplicit | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function isImplicit($rule)
{
return $rule instanceof ImplicitRule ||
in_array($rule, $this->implicitRules);
} | Determine if a given rule implies the attribute is required.
@param object|string $rule
@return bool | isImplicit | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function passesOptionalCheck($attribute)
{
if (! $this->hasRule($attribute, ['Sometimes'])) {
return true;
}
$data = ValidationData::initializeAndGatherData($attribute, $this->data);
return array_key_exists($attribute, $data)
|| array_key_exists($attribute, $this->data);
} | Determine if the attribute passes any optional check.
@param string $attribute
@return bool | passesOptionalCheck | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function isNotNullIfMarkedAsNullable($rule, $attribute)
{
if ($this->isImplicit($rule) || ! $this->hasRule($attribute, ['Nullable'])) {
return true;
}
return ! is_null(Arr::get($this->data, $attribute, 0));
} | Determine if the attribute fails the nullable check.
@param string $rule
@param string $attribute
@return bool | isNotNullIfMarkedAsNullable | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute)
{
return in_array($rule, ['Unique', 'Exists']) ? ! $this->messages->has($attribute) : true;
} | Determine if it's a necessary presence validation.
This is to avoid possible database type comparison errors.
@param string $rule
@param string $attribute
@return bool | hasNotFailedPreviousRuleIfPresenceRule | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function shouldStopValidating($attribute)
{
$cleanedAttribute = $this->replacePlaceholderInString($attribute);
if ($this->hasRule($attribute, ['Bail'])) {
return $this->messages->has($cleanedAttribute);
}
if (isset($this->failedRules[$cleanedAttribute]) &&
array_key_exists('uploaded', $this->failedRules[$cleanedAttribute])) {
return true;
}
// In case the attribute has any rule that indicates that the field is required
// and that rule already failed then we should stop validation at this point
// as now there is no point in calling other rules with this field empty.
return $this->hasRule($attribute, $this->implicitRules) &&
isset($this->failedRules[$cleanedAttribute]) &&
array_intersect(array_keys($this->failedRules[$cleanedAttribute]), $this->implicitRules);
} | Check if we should stop further validations on a given attribute.
@param string $attribute
@return bool | shouldStopValidating | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function addFailure($attribute, $rule, $parameters = [])
{
if (! $this->messages) {
$this->passes();
}
$attributeWithPlaceholders = $attribute;
$attribute = $this->replacePlaceholderInString($attribute);
if (in_array($rule, $this->excludeRules)) {
return $this->excludeAttribute($attribute);
}
if ($this->dependsOnOtherFields($rule)) {
$parameters = $this->replaceDotPlaceholderInParameters($parameters);
}
$this->messages->add($attribute, $this->makeReplacements(
$this->getMessage($attributeWithPlaceholders, $rule), $attribute, $rule, $parameters
));
$this->failedRules[$attribute][$rule] = $parameters;
} | Add a failed rule and error message to the collection.
@param string $attribute
@param string $rule
@param array $parameters
@return void | addFailure | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function excludeAttribute(string $attribute)
{
$this->excludeAttributes[] = $attribute;
$this->excludeAttributes = array_unique($this->excludeAttributes);
} | Add the given attribute to the list of excluded attributes.
@param string $attribute
@return void | excludeAttribute | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function valid()
{
if (! $this->messages) {
$this->passes();
}
return array_diff_key(
$this->data, $this->attributesThatHaveMessages()
);
} | Returns the data which was valid.
@return array | valid | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function attributesThatHaveMessages()
{
return (new Collection($this->messages()->toArray()))
->map(fn ($message, $key) => explode('.', $key)[0])
->unique()
->flip()
->all();
} | Generate an array of all attributes that have messages.
@return array | attributesThatHaveMessages | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function failed()
{
return $this->failedRules;
} | Get the failed validation rules.
@return array | failed | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function errors()
{
return $this->messages();
} | An alternative more semantic shortcut to the message container.
@return \Illuminate\Support\MessageBag | errors | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function hasRule($attribute, $rules)
{
return ! is_null($this->getRule($attribute, $rules));
} | Determine if the given attribute has a rule in the given set.
@param string $attribute
@param string|array $rules
@return bool | hasRule | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function attributes()
{
return $this->getData();
} | Get the data under validation.
@return array | attributes | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function setData(array $data)
{
$this->data = $this->parseData($data);
$this->setRules($this->initialRules);
return $this;
} | Set the data under validation.
@param array $data
@return $this | setData | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function getValue($attribute)
{
return Arr::get($this->data, $attribute);
} | Get the value of a given attribute.
@param string $attribute
@return mixed | getValue | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function getRulesWithoutPlaceholders()
{
return (new Collection($this->rules))
->mapWithKeys(fn ($value, $key) => [
str_replace('__dot__'.static::$placeholderHash, '\\.', $key) => $value,
])
->all();
} | Get the validation rules with key placeholders removed.
@return array | getRulesWithoutPlaceholders | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
private function dataForSometimesIteration(string $attribute, $removeLastSegmentOfAttribute)
{
$lastSegmentOfAttribute = strrchr($attribute, '.');
$attribute = $lastSegmentOfAttribute && $removeLastSegmentOfAttribute
? Str::replaceLast($lastSegmentOfAttribute, '', $attribute)
: $attribute;
return is_array($data = data_get($this->data, $attribute))
? new Fluent($data)
: $data;
} | Get the data that should be injected into the iteration of a wildcard "sometimes" callback.
@param string $attribute
@return \Illuminate\Support\Fluent|array|mixed | dataForSometimesIteration | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function stopOnFirstFailure($stopOnFirstFailure = true)
{
$this->stopOnFirstFailure = $stopOnFirstFailure;
return $this;
} | Instruct the validator to stop validating after the first rule failure.
@param bool $stopOnFirstFailure
@return $this | stopOnFirstFailure | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function addExtensions(array $extensions)
{
if ($extensions) {
$keys = array_map(Str::snake(...), array_keys($extensions));
$extensions = array_combine($keys, array_values($extensions));
}
$this->extensions = array_merge($this->extensions, $extensions);
} | Register an array of custom validator extensions.
@param array $extensions
@return void | addExtensions | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function addExtension($rule, $extension)
{
$this->extensions[Str::snake($rule)] = $extension;
} | Register a custom validator extension.
@param string $rule
@param \Closure|string $extension
@return void | addExtension | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function addImplicitExtension($rule, $extension)
{
$this->addExtension($rule, $extension);
$this->implicitRules[] = Str::studly($rule);
} | Register a custom implicit validator extension.
@param string $rule
@param \Closure|string $extension
@return void | addImplicitExtension | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function addDependentExtension($rule, $extension)
{
$this->addExtension($rule, $extension);
$this->dependentRules[] = Str::studly($rule);
} | Register a custom dependent validator extension.
@param string $rule
@param \Closure|string $extension
@return void | addDependentExtension | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function addReplacers(array $replacers)
{
if ($replacers) {
$keys = array_map(Str::snake(...), array_keys($replacers));
$replacers = array_combine($keys, array_values($replacers));
}
$this->replacers = array_merge($this->replacers, $replacers);
} | Register an array of custom validator message replacers.
@param array $replacers
@return void | addReplacers | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function setCustomMessages(array $messages)
{
$this->customMessages = array_merge($this->customMessages, $messages);
return $this;
} | Set the custom messages for the validator.
@param array $messages
@return $this | setCustomMessages | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function setAttributeNames(array $attributes)
{
$this->customAttributes = $attributes;
return $this;
} | Set the custom attributes on the validator.
@param array $attributes
@return $this | setAttributeNames | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function addCustomAttributes(array $attributes)
{
$this->customAttributes = array_merge($this->customAttributes, $attributes);
return $this;
} | Add custom attributes to the validator.
@param array $attributes
@return $this | addCustomAttributes | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function setImplicitAttributesFormatter(?callable $formatter = null)
{
$this->implicitAttributesFormatter = $formatter;
return $this;
} | Set the callback that used to format an implicit attribute.
@param callable|null $formatter
@return $this | setImplicitAttributesFormatter | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function setValueNames(array $values)
{
$this->customValues = $values;
return $this;
} | Set the custom values on the validator.
@param array $values
@return $this | setValueNames | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function addCustomValues(array $customValues)
{
$this->customValues = array_merge($this->customValues, $customValues);
return $this;
} | Add the custom values for the validator.
@param array $customValues
@return $this | addCustomValues | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function getPresenceVerifier($connection = null)
{
if (! isset($this->presenceVerifier)) {
throw new RuntimeException('Presence verifier has not been set.');
}
if ($this->presenceVerifier instanceof DatabasePresenceVerifierInterface) {
$this->presenceVerifier->setConnection($connection);
}
return $this->presenceVerifier;
} | Get the Presence Verifier implementation.
@param string|null $connection
@return \Illuminate\Validation\PresenceVerifierInterface
@throws \RuntimeException | getPresenceVerifier | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function setException($exception)
{
if (! is_a($exception, ValidationException::class, true)) {
throw new InvalidArgumentException(
sprintf('Exception [%s] is invalid. It must extend [%s].', $exception, ValidationException::class)
);
}
$this->exception = $exception;
return $this;
} | Set the exception to throw upon failed validation.
@param class-string<\Illuminate\Validation\ValidationException> $exception
@return $this
@throws \InvalidArgumentException | setException | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function ensureExponentWithinAllowedRangeUsing($callback)
{
$this->ensureExponentWithinAllowedRangeUsing = $callback;
return $this;
} | Ensure exponents are within range using the given callback.
@param callable(int $scale, string $attribute, mixed $value) $callback
@return $this | ensureExponentWithinAllowedRangeUsing | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function setTranslator(Translator $translator)
{
$this->translator = $translator;
} | Set the Translator implementation.
@param \Illuminate\Contracts\Translation\Translator $translator
@return void | setTranslator | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
protected function callClassBasedExtension($callback, $parameters)
{
[$class, $method] = Str::parseCallback($callback, 'validate');
return $this->container->make($class)->{$method}(...array_values($parameters));
} | Call a class based validator extension.
@param string $callback
@param array $parameters
@return bool | callClassBasedExtension | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public function __call($method, $parameters)
{
$rule = Str::snake(substr($method, 8));
if (isset($this->extensions[$rule])) {
return $this->callExtension($rule, $parameters);
}
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
} | Handle dynamic calls to class methods.
@param string $method
@param array $parameters
@return mixed
@throws \BadMethodCallException | __call | php | laravel/framework | src/Illuminate/Validation/Validator.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Validator.php | MIT |
public static function can($ability, ...$arguments)
{
return new Can($ability, $arguments);
} | Get a can constraint builder instance.
@param string $ability
@param mixed ...$arguments
@return \Illuminate\Validation\Rules\Can | can | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function when($condition, $rules, $defaultRules = [])
{
return new ConditionalRules($condition, $rules, $defaultRules);
} | Apply the given rules if the given condition is truthy.
@param callable|bool $condition
@param \Illuminate\Contracts\Validation\ValidationRule|\Illuminate\Contracts\Validation\InvokableRule|\Illuminate\Contracts\Validation\Rule|\Closure|array|string $rules
@param \Illuminate\Contracts\Validation\ValidationRule|\Illuminate\Contracts\Validation\InvokableRule|\Illuminate\Contracts\Validation\Rule|\Closure|array|string $defaultRules
@return \Illuminate\Validation\ConditionalRules | when | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function unless($condition, $rules, $defaultRules = [])
{
return new ConditionalRules($condition, $defaultRules, $rules);
} | Apply the given rules if the given condition is falsy.
@param callable|bool $condition
@param \Illuminate\Contracts\Validation\ValidationRule|\Illuminate\Contracts\Validation\InvokableRule|\Illuminate\Contracts\Validation\Rule|\Closure|array|string $rules
@param \Illuminate\Contracts\Validation\ValidationRule|\Illuminate\Contracts\Validation\InvokableRule|\Illuminate\Contracts\Validation\Rule|\Closure|array|string $defaultRules
@return \Illuminate\Validation\ConditionalRules | unless | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function array($keys = null)
{
return new ArrayRule(...func_get_args());
} | Get an array rule builder instance.
@param array|null $keys
@return \Illuminate\Validation\Rules\ArrayRule | array | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function unique($table, $column = 'NULL')
{
return new Unique($table, $column);
} | Get a unique constraint builder instance.
@param string $table
@param string $column
@return \Illuminate\Validation\Rules\Unique | unique | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function exists($table, $column = 'NULL')
{
return new Exists($table, $column);
} | Get an exists constraint builder instance.
@param string $table
@param string $column
@return \Illuminate\Validation\Rules\Exists | exists | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function in($values)
{
if ($values instanceof Arrayable) {
$values = $values->toArray();
}
return new In(is_array($values) ? $values : func_get_args());
} | Get an in rule builder instance.
@param \Illuminate\Contracts\Support\Arrayable|\BackedEnum|\UnitEnum|array|string $values
@return \Illuminate\Validation\Rules\In | in | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function notIn($values)
{
if ($values instanceof Arrayable) {
$values = $values->toArray();
}
return new NotIn(is_array($values) ? $values : func_get_args());
} | Get a not_in rule builder instance.
@param \Illuminate\Contracts\Support\Arrayable|\BackedEnum|\UnitEnum|array|string $values
@return \Illuminate\Validation\Rules\NotIn | notIn | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function requiredIf($callback)
{
return new RequiredIf($callback);
} | Get a required_if rule builder instance.
@param callable|bool $callback
@return \Illuminate\Validation\Rules\RequiredIf | requiredIf | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function excludeIf($callback)
{
return new ExcludeIf($callback);
} | Get a exclude_if rule builder instance.
@param callable|bool $callback
@return \Illuminate\Validation\Rules\ExcludeIf | excludeIf | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function prohibitedIf($callback)
{
return new ProhibitedIf($callback);
} | Get a prohibited_if rule builder instance.
@param callable|bool $callback
@return \Illuminate\Validation\Rules\ProhibitedIf | prohibitedIf | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function date()
{
return new Date;
} | Get a date rule builder instance.
@return \Illuminate\Validation\Rules\Date | date | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function email()
{
return new Email;
} | Get an email rule builder instance.
@return \Illuminate\Validation\Rules\Email | email | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function enum($type)
{
return new Enum($type);
} | Get an enum rule builder instance.
@param class-string $type
@return \Illuminate\Validation\Rules\Enum | enum | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function file()
{
return new File;
} | Get a file rule builder instance.
@return \Illuminate\Validation\Rules\File | file | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function imageFile($allowSvg = false)
{
return new ImageFile($allowSvg);
} | Get an image file rule builder instance.
@param bool $allowSvg
@return \Illuminate\Validation\Rules\ImageFile | imageFile | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function dimensions(array $constraints = [])
{
return new Dimensions($constraints);
} | Get a dimensions rule builder instance.
@param array $constraints
@return \Illuminate\Validation\Rules\Dimensions | dimensions | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function numeric()
{
return new Numeric;
} | Get a numeric rule builder instance.
@return \Illuminate\Validation\Rules\Numeric | numeric | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public static function anyOf($rules)
{
return new AnyOf($rules);
} | Get an "any of" rule builder instance.
@param array
@return \Illuminate\Validation\Rules\AnyOf
@throws \InvalidArgumentException | anyOf | php | laravel/framework | src/Illuminate/Validation/Rule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rule.php | MIT |
public function __construct($condition, $rules, $defaultRules = [])
{
$this->condition = $condition;
$this->rules = $rules;
$this->defaultRules = $defaultRules;
} | Create a new conditional rules instance.
@param callable|bool $condition
@param \Illuminate\Contracts\Validation\ValidationRule|\Illuminate\Contracts\Validation\InvokableRule|\Illuminate\Contracts\Validation\Rule|\Closure|array|string $rules
@param \Illuminate\Contracts\Validation\ValidationRule|\Illuminate\Contracts\Validation\InvokableRule|\Illuminate\Contracts\Validation\Rule|\Closure|array|string $defaultRules | __construct | php | laravel/framework | src/Illuminate/Validation/ConditionalRules.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ConditionalRules.php | MIT |
public function passes(array $data = [])
{
return is_callable($this->condition)
? call_user_func($this->condition, new Fluent($data))
: $this->condition;
} | Determine if the conditional rules should be added.
@param array $data
@return bool | passes | php | laravel/framework | src/Illuminate/Validation/ConditionalRules.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ConditionalRules.php | MIT |
protected function prepareForValidation()
{
//
} | Prepare the data for validation.
@return void | prepareForValidation | php | laravel/framework | src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | MIT |
protected function getValidatorInstance()
{
return $this->validator();
} | Get the validator instance for the request.
@return \Illuminate\Validation\Validator | getValidatorInstance | php | laravel/framework | src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | MIT |
protected function passedValidation()
{
//
} | Handle a passed validation attempt.
@return void | passedValidation | php | laravel/framework | src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | MIT |
protected function failedValidation(Validator $validator)
{
$exception = $validator->getException();
throw new $exception($validator);
} | Handle a failed validation attempt.
@param \Illuminate\Validation\Validator $validator
@return void
@throws \Illuminate\Validation\ValidationException | failedValidation | php | laravel/framework | src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | MIT |
protected function failedAuthorization()
{
throw new UnauthorizedException;
} | Handle a failed authorization attempt.
@return void
@throws \Illuminate\Validation\UnauthorizedException | failedAuthorization | php | laravel/framework | src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | MIT |
public function __construct(Translator $translator, ?Container $container = null)
{
$this->container = $container;
$this->translator = $translator;
} | Create a new Validator factory instance.
@param \Illuminate\Contracts\Translation\Translator $translator
@param \Illuminate\Contracts\Container\Container|null $container | __construct | php | laravel/framework | src/Illuminate/Validation/Factory.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Factory.php | MIT |
public function where($column, $value = null)
{
if ($value instanceof Arrayable || is_array($value)) {
return $this->whereIn($column, $value);
}
if ($column instanceof Closure) {
return $this->using($column);
}
if (is_null($value)) {
return $this->whereNull($column);
}
$value = enum_value($value);
$this->wheres[] = compact('column', 'value');
return $this;
} | Set a "where" constraint on the query.
@param \Closure|string $column
@param \Illuminate\Contracts\Support\Arrayable|\UnitEnum|\Closure|array|string|int|bool|null $value
@return $this | where | php | laravel/framework | src/Illuminate/Validation/Rules/DatabaseRule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/DatabaseRule.php | MIT |
public function whereNot($column, $value)
{
if ($value instanceof Arrayable || is_array($value)) {
return $this->whereNotIn($column, $value);
}
$value = enum_value($value);
return $this->where($column, '!'.$value);
} | Set a "where not" constraint on the query.
@param string $column
@param \Illuminate\Contracts\Support\Arrayable|\UnitEnum|array|string $value
@return $this | whereNot | php | laravel/framework | src/Illuminate/Validation/Rules/DatabaseRule.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/DatabaseRule.php | MIT |
public function __construct(array $constraints = [])
{
$this->constraints = $constraints;
} | Create a new dimensions rule instance.
@param array $constraints | __construct | php | laravel/framework | src/Illuminate/Validation/Rules/Dimensions.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/Dimensions.php | MIT |
public function minWidth($value)
{
$this->constraints['min_width'] = $value;
return $this;
} | Set the "min width" constraint.
@param int $value
@return $this | minWidth | php | laravel/framework | src/Illuminate/Validation/Rules/Dimensions.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/Dimensions.php | MIT |
public function minHeight($value)
{
$this->constraints['min_height'] = $value;
return $this;
} | Set the "min height" constraint.
@param int $value
@return $this | minHeight | php | laravel/framework | src/Illuminate/Validation/Rules/Dimensions.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/Dimensions.php | MIT |
public function maxWidth($value)
{
$this->constraints['max_width'] = $value;
return $this;
} | Set the "max width" constraint.
@param int $value
@return $this | maxWidth | php | laravel/framework | src/Illuminate/Validation/Rules/Dimensions.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/Dimensions.php | MIT |
public function maxHeight($value)
{
$this->constraints['max_height'] = $value;
return $this;
} | Set the "max height" constraint.
@param int $value
@return $this | maxHeight | php | laravel/framework | src/Illuminate/Validation/Rules/Dimensions.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/Dimensions.php | MIT |
public function __construct($rules)
{
if (! is_array($rules)) {
throw new InvalidArgumentException('The provided value must be an array of validation rules.');
}
$this->rules = $rules;
} | Sets the validation rules to match against.
@param Illuminate\Contracts\Validation\ValidationRule[][] $rules
@throws \InvalidArgumentException | __construct | php | laravel/framework | src/Illuminate/Validation/Rules/AnyOf.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/AnyOf.php | MIT |
public function message()
{
$message = $this->validator->getTranslator()->get('validation.any_of');
return $message === 'validation.any_of'
? ['The :attribute field is invalid.']
: $message;
} | Get the validation error messages.
@return array | message | php | laravel/framework | src/Illuminate/Validation/Rules/AnyOf.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/AnyOf.php | MIT |
public static function defaults($callback = null)
{
if (is_null($callback)) {
return static::default();
}
if (! is_callable($callback) && ! $callback instanceof static) {
throw new InvalidArgumentException('The given callback should be callable or an instance of '.static::class);
}
static::$defaultCallback = $callback;
} | Set the default callback to be used for determining the file default rules.
If no arguments are passed, the default file rule configuration will be returned.
@param static|callable|null $callback
@return static|void | defaults | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
public static function image($allowSvg = false)
{
return new ImageFile($allowSvg);
} | Limit the uploaded file to only image types.
@param bool $allowSvg
@return ImageFile | image | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
public static function types($mimetypes)
{
return tap(new static(), fn ($file) => $file->allowedMimetypes = (array) $mimetypes);
} | Limit the uploaded file to the given MIME types or file extensions.
@param string|array<int, string> $mimetypes
@return static | types | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
public function extensions($extensions)
{
$this->allowedExtensions = (array) $extensions;
return $this;
} | Limit the uploaded file to the given file extensions.
@param string|array<int, string> $extensions
@return $this | extensions | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
public function size($size)
{
$this->minimumFileSize = $this->toKilobytes($size);
$this->maximumFileSize = $this->minimumFileSize;
return $this;
} | Indicate that the uploaded file should be exactly a certain size in kilobytes.
@param string|int $size
@return $this | size | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
public function between($minSize, $maxSize)
{
$this->minimumFileSize = $this->toKilobytes($minSize);
$this->maximumFileSize = $this->toKilobytes($maxSize);
return $this;
} | Indicate that the uploaded file should be between a minimum and maximum size in kilobytes.
@param string|int $minSize
@param string|int $maxSize
@return $this | between | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
public function min($size)
{
$this->minimumFileSize = $this->toKilobytes($size);
return $this;
} | Indicate that the uploaded file should be no less than the given number of kilobytes.
@param string|int $size
@return $this | min | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
public function max($size)
{
$this->maximumFileSize = $this->toKilobytes($size);
return $this;
} | Indicate that the uploaded file should be no more than the given number of kilobytes.
@param string|int $size
@return $this | max | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
public function rules($rules)
{
$this->customRules = array_merge($this->customRules, Arr::wrap($rules));
return $this;
} | Specify additional validation rules that should be merged with the default rules during validation.
@param string|array $rules
@return $this | rules | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
protected function fail($messages)
{
$messages = Collection::wrap($messages)
->map(fn ($message) => $this->validator->getTranslator()->get($message))
->all();
$this->messages = array_merge($this->messages, $messages);
return false;
} | Adds the given failures, and return false.
@param array|string $messages
@return bool | fail | php | laravel/framework | src/Illuminate/Validation/Rules/File.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Validation/Rules/File.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.