diff --git a/src/Illuminate/Validation/Rule.php b/src/Illuminate/Validation/Rule.php index 9598dacc30f5..365aa320d3d6 100644 --- a/src/Illuminate/Validation/Rule.php +++ b/src/Illuminate/Validation/Rule.php @@ -5,23 +5,6 @@ use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Arr; use Illuminate\Support\Traits\Macroable; -use Illuminate\Validation\Rules\AnyOf; -use Illuminate\Validation\Rules\ArrayRule; -use Illuminate\Validation\Rules\Can; -use Illuminate\Validation\Rules\Date; -use Illuminate\Validation\Rules\Dimensions; -use Illuminate\Validation\Rules\Email; -use Illuminate\Validation\Rules\Enum; -use Illuminate\Validation\Rules\ExcludeIf; -use Illuminate\Validation\Rules\Exists; -use Illuminate\Validation\Rules\File; -use Illuminate\Validation\Rules\ImageFile; -use Illuminate\Validation\Rules\In; -use Illuminate\Validation\Rules\NotIn; -use Illuminate\Validation\Rules\Numeric; -use Illuminate\Validation\Rules\ProhibitedIf; -use Illuminate\Validation\Rules\RequiredIf; -use Illuminate\Validation\Rules\Unique; class Rule { @@ -36,7 +19,7 @@ class Rule */ public static function can($ability, ...$arguments) { - return new Can($ability, $arguments); + return new Rules\Can($ability, $arguments); } /** @@ -66,14 +49,248 @@ public static function unless($condition, $rules, $defaultRules = []) } /** - * Get an array rule builder instance. + * Get an "active_url" validation rule. + * + * @return string + */ + public static function activeUrl() + { + return 'active_url'; + } + + /** + * Get an "accepted" validation rule. + * + * @return string + */ + public static function accepted() + { + return 'accepted'; + } + + /** + * Get a "accepted_if" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\AcceptedIf + */ + public static function acceptedIf($anotherField, $value) + { + return new Rules\AcceptedIf($anotherField, $value); + } + + /** + * Get an "alpha" rule builder instance. + * + * @return \Illuminate\Validation\Rules\Alpha + */ + public static function alpha() + { + return new Rules\Alpha; + } + + /** + * Get a "mac_address" validation rule. + * + * @return string + */ + public static function macAddress() + { + return 'mac_address'; + } + + /** + * Get an "alpha_dash" rule builder instance. + * + * @return \Illuminate\Validation\Rules\AlphaDash + */ + public static function alphaDash() + { + return new Rules\AlphaDash; + } + + /** + * Get an "alpha_num" rule builder instance. + * + * @return \Illuminate\Validation\Rules\AlphaNum + */ + public static function alphaNum() + { + return new Rules\AlphaNum; + } + + /** + * Get an "ascii" validation rule. + * + * @return string + */ + public static function ascii() + { + return 'ascii'; + } + + /** + * Get a "boolean" validation rule. + * + * @return string + */ + public static function boolean() + { + return 'boolean'; + } + + /** + * Get a "declined_if" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\DeclinedIf + */ + public static function declinedIf($anotherField, $value) + { + return new Rules\DeclinedIf($anotherField, $value); + } + + /** + * Get a "present_if" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\PresentIf + */ + public static function presentIf($anotherField, $value) + { + return new Rules\PresentIf($anotherField, $value); + } + + /** + * Get a "declined" validation rule. + * + * @return string + */ + public static function declined() + { + return 'declined'; + } + + /** + * Get a "confirmed" rule builder instance. + * + * @return \Illuminate\Validation\Rules\Confirmed + */ + public static function confirmed() + { + return new Rules\Confirmed; + } + + /** + * Get a "current_password" rule builder instance. + * + * @return \Illuminate\Validation\Rules\CurrentPassword + */ + public static function currentPassword() + { + return new Rules\CurrentPassword; + } + + /** + * Get a "doesnt_start_with" rule builder instance. + * + * @param array $values + * @return \Illuminate\Validation\Rules\DoesntStartWith + */ + public static function doesntStartWith($values) + { + return new Rules\DoesntStartWith($values); + } + + /** + * Get a "timezone" rule builder instance. + * + * @param array|null $values + * @return \Illuminate\Validation\Rules\Timezone + */ + public static function timezone($values = null) + { + return new Rules\Timezone($values); + } + + /** + * Get an "starts_with" rule builder instance. + * + * @param array $values + * @return \Illuminate\Validation\Rules\StartsWith + */ + public static function startsWith($values) + { + return new Rules\StartsWith($values); + } + + /** + * Get a "doesnt_end_with" rule builder instance. + * + * @param array $values + * @return \Illuminate\Validation\Rules\DoesntEndWith + */ + public static function doesntEndWith($values) + { + return new Rules\DoesntEndWith($values); + } + + /** + * Get an "ends_with" rule builder instance. + * + * @param array $values + * @return \Illuminate\Validation\Rules\EndsWith + */ + public static function endsWith($values) + { + return new Rules\EndsWith($values); + } + + /** + * Get a "different" rule builder instance. + * + * @param string $field + * @return \Illuminate\Validation\Rules\Different + */ + public static function different($field) + { + return new Rules\Different($field); + } + + /** + * Get a "size" rule builder instance. + * + * @param int|float $value + * @return \Illuminate\Validation\Rules\Size + */ + public static function size($value) + { + return new Rules\Size($value); + } + + /** + * Get a "same" rule builder instance. + * + * @param string $field + * @return \Illuminate\Validation\Rules\Same + */ + public static function same($field) + { + return new Rules\Same($field); + } + + /** + * Get an "array" rule builder instance. * * @param array|null $keys - * @return \Illuminate\Validation\Rules\ArrayRule + * @return \Illuminate\Validation\Rules\Arr */ public static function array($keys = null) { - return new ArrayRule(...func_get_args()); + return new Rules\Arr(...func_get_args()); } /** @@ -96,11 +313,11 @@ public static function forEach($callback) */ public static function unique($table, $column = 'NULL') { - return new Unique($table, $column); + return new Rules\Unique($table, $column); } /** - * Get an exists constraint builder instance. + * Get an "exists" constraint builder instance. * * @param string $table * @param string $column @@ -108,11 +325,11 @@ public static function unique($table, $column = 'NULL') */ public static function exists($table, $column = 'NULL') { - return new Exists($table, $column); + return new Rules\Exists($table, $column); } /** - * Get an in rule builder instance. + * Get an "in" rule builder instance. * * @param \Illuminate\Contracts\Support\Arrayable|\BackedEnum|\UnitEnum|array|string $values * @return \Illuminate\Validation\Rules\In @@ -123,11 +340,11 @@ public static function in($values) $values = $values->toArray(); } - return new In(is_array($values) ? $values : func_get_args()); + return new Rules\In(is_array($values) ? $values : func_get_args()); } /** - * Get a not_in rule builder instance. + * Get a "not_in" rule builder instance. * * @param \Illuminate\Contracts\Support\Arrayable|\BackedEnum|\UnitEnum|array|string $values * @return \Illuminate\Validation\Rules\NotIn @@ -138,117 +355,842 @@ public static function notIn($values) $values = $values->toArray(); } - return new NotIn(is_array($values) ? $values : func_get_args()); + return new Rules\NotIn(is_array($values) ? $values : func_get_args()); } /** - * Get a required_if rule builder instance. + * Get a "max" rule builder instance. * - * @param callable|bool $callback - * @return \Illuminate\Validation\Rules\RequiredIf + * @param callable|int $value + * @return \Illuminate\Validation\Rules\Max */ - public static function requiredIf($callback) + public static function max($value) { - return new RequiredIf($callback); + return new Rules\Max($value); } /** - * Get a exclude_if rule builder instance. + * Get a "regex" rule builder instance. * - * @param callable|bool $callback - * @return \Illuminate\Validation\Rules\ExcludeIf + * @param string $value + * @return \Illuminate\Validation\Rules\Regex */ - public static function excludeIf($callback) + public static function regex($value) { - return new ExcludeIf($callback); + return new Rules\Regex($value); } /** - * Get a prohibited_if rule builder instance. + * Get a "not_regex" rule builder instance. * - * @param callable|bool $callback - * @return \Illuminate\Validation\Rules\ProhibitedIf + * @param string $value + * @return \Illuminate\Validation\Rules\NotRegex */ - public static function prohibitedIf($callback) + public static function notRegex($value) + { + return new Rules\NotRegex($value); + } + + /** + * Get an "ip" rule builder instance. + * + * @return \Illuminate\Validation\Rules\IpAddress + */ + public static function ip() + { + return new Rules\IpAddress; + } + + /** + * Get an "uuid" rule builder instance. + * + * @return \Illuminate\Validation\Rules\Uuid + */ + public static function uuid() + { + return new Rules\Uuid; + } + + /** + * Get a "json" validation rule. + * + * @return string + */ + public static function json() + { + return 'json'; + } + + /** + * Get a "sometimes" validation rule. + * + * @return string + */ + public static function sometimes() + { + return 'sometimes'; + } + + /** + * Get a "nullable" validation rule. + * + * @return string + */ + public static function nullable() + { + return 'nullable'; + } + + /** + * Get a "min" rule builder instance. + * + * @param callable|int $value + * @return \Illuminate\Validation\Rules\Min + */ + public static function min($value) + { + return new Rules\Min($value); + } + + /** + * Get a "decimal" rule builder instance. + * + * @param int $minPlaces + * @param int|null $maxPlaces + * @return \Illuminate\Validation\Rules\Decimal + */ + public static function decimal($minPlaces, $maxPlaces = null) + { + return new Rules\Decimal($minPlaces, $maxPlaces); + } + + /** + * Get a "between" rule builder instance. + * + * @param int|float $min + * @param int|float $max + * @return \Illuminate\Validation\Rules\Between + */ + public static function between($min, $max) + { + return new Rules\Between($min, $max); + } + + /** + * Get a "exclude_unless" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\ExcludeUnless + */ + public static function excludeUnless($anotherField, $value) + { + return new Rules\ExcludeUnless($anotherField, $value); + } + + /** + * Get a "missing_if" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\MissingIf + */ + public static function missingIf($anotherField, $value) + { + return new Rules\MissingIf($anotherField, $value); + } + + /** + * Get a "missing_unless" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\MissingUnless + */ + public static function missingUnless($anotherField, $value) + { + return new Rules\MissingUnless($anotherField, $value); + } + + /** + * Get a "exclude_with" rule builder instance. + * + * @param string $anotherField + * @return \Illuminate\Validation\Rules\ExcludeWith + */ + public static function excludeWith($anotherField) + { + return new Rules\ExcludeWith($anotherField); + } + + /** + * Get a "exclude_without" rule builder instance. + * + * @param string $anotherField + * @return \Illuminate\Validation\Rules\ExcludeWithout + */ + public static function excludeWithout($anotherField) + { + return new Rules\ExcludeWithout($anotherField); + } + + /** + * Get a "mimetypes" rule builder instance. + * + * @param array $types + * @return \Illuminate\Validation\Rules\MimeTypes + */ + public static function mimeTypes($types) + { + return new Rules\MimeTypes($types); + } + + /** + * Get a "mimes" rule builder instance. + * + * @param array $types + * @return \Illuminate\Validation\Rules\Mimes + */ + public static function mimes($types) + { + return new Rules\Mimes($types); + } + + /** + * Get a "prohibits" rule builder instance. + * + * @param array $types + * @return \Illuminate\Validation\Rules\Prohibits + */ + public static function prohibits($types) + { + return new Rules\Prohibits($types); + } + + /** + * Get a "required_array_keys" rule builder instance. + * + * @param array $keys + * @return \Illuminate\Validation\Rules\RequiredArrayKeys + */ + public static function requiredArrayKeys($keys) + { + return new Rules\RequiredArrayKeys($keys); + } + + /** + * Get a "required" validation rule. + * + * @return string + */ + public static function required() + { + return 'required'; + } + + /** + * Get a "prohibited" validation rule. + * + * @return string + */ + public static function prohibited() + { + return 'prohibited'; + } + + /** + * Get a "present" validation rule. + * + * @return string + */ + public static function present() + { + return 'present'; + } + + /** + * Get an "exclude" validation rule. + * + * @return string + */ + public static function exclude() + { + return 'exclude'; + } + + /** + * Get a "missing" validation rule. + * + * @return string + */ + public static function missing() + { + return 'missing'; + } + + /** + * Get a "list" validation rule. + * + * @return string + */ + public static function list() + { + return 'list'; + } + + /** + * Get a "bail" validation rule. + * + * @return string + */ + public static function bail() + { + return 'bail'; + } + + /** + * Get a "filled" validation rule. + * + * @return string + */ + public static function filled() + { + return 'filled'; + } + + /** + * Get an "integer" validation rule. + * + * @return string + */ + public static function integer() + { + return 'integer'; + } + + /** + * Get a "url" rule builder instance. + * + * @return \Illuminate\Validation\Rules\Url + */ + public static function url() + { + return new Rules\Url; + } + + /** + * Get a "digits" rule builder instance. + * + * @param int $digits + * @return \Illuminate\Validation\Rules\Digits + */ + public static function digits($digits) + { + return new Rules\Digits($digits); + } + + /** + * Get a "max_digits" rule builder instance. + * + * @param int $value + * @return \Illuminate\Validation\Rules\MaxDigits + */ + public static function maxDigits($value) + { + return new Rules\MaxDigits($value); + } + + /** + * Get a "gt" rule builder instance. + * + * @param string|int $value + * @return \Illuminate\Validation\Rules\GreaterThan + */ + public static function greaterThan($value) + { + return new Rules\GreaterThan($value); + } + + /** + * Get a "gt" rule builder instance. + * + * @param string|int $value + * @return \Illuminate\Validation\Rules\GreaterThan + */ + public static function gt($value) + { + return new Rules\GreaterThan($value); + } + + /** + * Get a "gte" rule builder instance. + * + * @param string|int $value + * @return \Illuminate\Validation\Rules\GreaterThanOrEqual + */ + public static function greaterThanOrEqual($value) + { + return new Rules\GreaterThanOrEqual($value); + } + + /** + * Get a "gte" rule builder instance. + * + * @param string|int $value + * @return \Illuminate\Validation\Rules\GreaterThanOrEqual + */ + public static function gte($value) + { + return new Rules\GreaterThanOrEqual($value); + } + + /** + * Get a "lt" rule builder instance. + * + * @param string|int $value + * @return \Illuminate\Validation\Rules\LessThan + */ + public static function lessThan($value) + { + return new Rules\LessThan($value); + } + + /** + * Get a "lt" rule builder instance. + * + * @param string|int $value + * @return \Illuminate\Validation\Rules\LessThan + */ + public static function lt($value) + { + return new Rules\LessThan($value); + } + + /** + * Get a "lte" rule builder instance. + * + * @param string|int $value + * @return \Illuminate\Validation\Rules\LessThanOrEqual + */ + public static function lessThanOrEqual($value) + { + return new Rules\LessThanOrEqual($value); + } + + /** + * Get a "lte" rule builder instance. + * + * @param string|int $value + * @return \Illuminate\Validation\Rules\LessThanOrEqual + */ + public static function lte($value) + { + return new Rules\LessThanOrEqual($value); + } + + /** + * Get a "multiple_of" rule builder instance. + * + * @param int|float $value + * @return \Illuminate\Validation\Rules\MultipleOf + */ + public static function multipleOf($value) + { + return new Rules\MultipleOf($value); + } + + /** + * Get an "in_array" rule builder instance. + * + * @param string $value + * @return \Illuminate\Validation\Rules\InArray + */ + public static function inArray($value) + { + return new Rules\InArray($value); + } + + /** + * Get an "in_array_keys" rule builder instance. + * + * @param array $value + * @return \Illuminate\Validation\Rules\InArrayKeys + */ + public static function inArrayKeys($value) + { + return new Rules\InArrayKeys($value); + } + + /** + * Get a "distinct" rule builder instance. + * + * @return \Illuminate\Validation\Rules\Distinct + */ + public static function distinct() + { + return new Rules\Distinct(); + } + + /** + * Get a "max_digits" rule builder instance. + * + * @param int $value + * @return \Illuminate\Validation\Rules\MinDigits + */ + public static function minDigits($value) + { + return new Rules\MinDigits($value); + } + + /** + * Get a "digits_between" rule builder instance. + * + * @param int $min + * @param int $max + * @return \Illuminate\Validation\Rules\DigitsBetween + */ + public static function digitsBetween($min, $max) + { + return new Rules\DigitsBetween($min, $max); + } + + /** + * Get an "extensions" rule builder instance. + * + * @param array $extensions + * @return \Illuminate\Validation\Rules\Extensions + */ + public static function extensions($extensions = []) + { + return new Rules\Extensions($extensions); + } + + /** + * Get a "lowercase" validation rule. + * + * @return string + */ + public static function lowercase() + { + return 'lowercase'; + } + + /** + * Get an "uppercase" validation rule. + * + * @return string + */ + public static function uppercase() + { + return 'uppercase'; + } + + /** + * Get a "ulid" validation rule. + * + * @return string + */ + public static function ulid() + { + return 'ulid'; + } + + /** + * Get a required_if rule builder instance. + * + * @param callable|bool $callback + * @return \Illuminate\Validation\Rules\RequiredIf + */ + public static function requiredIf($callback) + { + return new Rules\RequiredIf($callback); + } + + /** + * Get a "string" validation rule. + * + * @return string + */ + public static function string() + { + return 'string'; + } + + /** + * Get a "hex_color" validation rule. + * + * @return string + */ + public static function hexColor() + { + return 'hex_color'; + } + + /** + * Get an "exclude_if" rule builder instance. + * + * @param callable|bool $callback + * @return \Illuminate\Validation\Rules\ExcludeIf + */ + public static function excludeIf($callback) + { + return new Rules\ExcludeIf($callback); + } + + /** + * Get a "missing_with" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\MissingWith + */ + public static function missingWith($fields) + { + return new Rules\MissingWith($fields); + } + + /** + * Get a "missing_with_all" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\MissingWithAll + */ + public static function missingWithAll($fields) + { + return new Rules\MissingWithAll($fields); + } + + /** + * Get a "present_with" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\PresentWith + */ + public static function presentWith($fields) + { + return new Rules\PresentWith($fields); + } + + /** + * Get a "present_with_all" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\PresentWithAll + */ + public static function presentWithAll($fields) + { + return new Rules\PresentWithAll($fields); + } + + /** + * Get a "required_with" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\RequiredWith + */ + public static function requiredWith($fields) + { + return new Rules\RequiredWith($fields); + } + + /** + * Get a "prohibited_if_accepted" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\ProhibitedIfAccepted + */ + public static function prohibitedIfAccepted($fields) + { + return new Rules\ProhibitedIfAccepted($fields); + } + + /** + * Get a "prohibited_if_declined" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\ProhibitedIfDeclined + */ + public static function prohibitedIfDeclined($fields) + { + return new Rules\ProhibitedIfDeclined($fields); + } + + /** + * Get a "required_if_accepted" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\RequiredIfAccepted + */ + public static function requiredIfAccepted($fields) + { + return new Rules\RequiredIfAccepted($fields); + } + + /** + * Get a "required_if_declined" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\RequiredIfDeclined + */ + public static function requiredIfDeclined($fields) + { + return new Rules\RequiredIfDeclined($fields); + } + + /** + * Get a "required_with_all" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\RequiredWithAll + */ + public static function requiredWithAll($fields) + { + return new Rules\RequiredWithAll($fields); + } + + /** + * Get a "required_without" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\RequiredWithout + */ + public static function requiredWithout($fields) + { + return new Rules\RequiredWithout($fields); + } + + /** + * Get a "required_without_all" rule builder instance. + * + * @param array $fields + * @return \Illuminate\Validation\Rules\RequiredWithoutAll + */ + public static function requiredWithoutAll($fields) + { + return new Rules\RequiredWithoutAll($fields); + } + + /** + * Get a prohibited_if rule builder instance. + * + * @param callable|bool $callback + * @return \Illuminate\Validation\Rules\ProhibitedIf + */ + public static function prohibitedIf($callback) + { + return new Rules\ProhibitedIf($callback); + } + + /** + * Get a "prohibited_unless" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\ProhibitedUnless + */ + public static function prohibitedUnless($anotherField, $value) + { + return new Rules\ProhibitedUnless($anotherField, $value); + } + + /** + * Get a "present_unless" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\PresentUnless + */ + public static function presentUnless($anotherField, $value) + { + return new Rules\PresentUnless($anotherField, $value); + } + + /** + * Get a "required_unless" rule builder instance. + * + * @param string $anotherField + * @param string|null|int|float $value + * @return \Illuminate\Validation\Rules\RequiredUnless + */ + public static function requiredUnless($anotherField, $value) { - return new ProhibitedIf($callback); + return new Rules\RequiredUnless($anotherField, $value); } /** - * Get a date rule builder instance. + * Get a "date" rule builder instance. * * @return \Illuminate\Validation\Rules\Date */ public static function date() { - return new Date; + return new Rules\Date; } /** - * Get an email rule builder instance. + * Get an "email" rule builder instance. * * @return \Illuminate\Validation\Rules\Email */ public static function email() { - return new Email; + return new Rules\Email; } /** - * Get an enum rule builder instance. + * Get an "enum" rule builder instance. * * @param class-string $type * @return \Illuminate\Validation\Rules\Enum */ public static function enum($type) { - return new Enum($type); + return new Rules\Enum($type); } /** - * Get a file rule builder instance. + * Get a "file" rule builder instance. * * @return \Illuminate\Validation\Rules\File */ public static function file() { - return new File; + return new Rules\File; } /** - * Get an image file rule builder instance. + * Get an "image" file rule builder instance. * * @param bool $allowSvg * @return \Illuminate\Validation\Rules\ImageFile */ public static function imageFile($allowSvg = false) { - return new ImageFile($allowSvg); + return new Rules\ImageFile($allowSvg); } /** - * Get a dimensions rule builder instance. + * Get a "dimensions" rule builder instance. * * @param array $constraints * @return \Illuminate\Validation\Rules\Dimensions */ public static function dimensions(array $constraints = []) { - return new Dimensions($constraints); + return new Rules\Dimensions($constraints); } /** - * Get a numeric rule builder instance. + * Get a "numeric" rule builder instance. * * @return \Illuminate\Validation\Rules\Numeric */ public static function numeric() { - return new Numeric; + return new Rules\Numeric; } /** - * Get an "any of" rule builder instance. + * Get an "any_of" rule builder instance. * * @param array $rules * @return \Illuminate\Validation\Rules\AnyOf @@ -257,11 +1199,11 @@ public static function numeric() */ public static function anyOf($rules) { - return new AnyOf($rules); + return new Rules\AnyOf($rules); } /** - * Get a contains rule builder instance. + * Get a "contains" rule builder instance. * * @param \Illuminate\Contracts\Support\Arrayable|\BackedEnum|\UnitEnum|array|string $values * @return \Illuminate\Validation\Rules\Contains diff --git a/src/Illuminate/Validation/Rules/AcceptedIf.php b/src/Illuminate/Validation/Rules/AcceptedIf.php new file mode 100644 index 000000000000..d604da127413 --- /dev/null +++ b/src/Illuminate/Validation/Rules/AcceptedIf.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/Alpha.php b/src/Illuminate/Validation/Rules/Alpha.php new file mode 100644 index 000000000000..c375ec318b2c --- /dev/null +++ b/src/Illuminate/Validation/Rules/Alpha.php @@ -0,0 +1,22 @@ +isAscii = true; + + return $this; + } + + public function __toString(): string + { + return 'alpha'.($this->isAscii ? ':ascii' : ''); + } +} diff --git a/src/Illuminate/Validation/Rules/AlphaDash.php b/src/Illuminate/Validation/Rules/AlphaDash.php new file mode 100644 index 000000000000..6dd01f1aba99 --- /dev/null +++ b/src/Illuminate/Validation/Rules/AlphaDash.php @@ -0,0 +1,22 @@ +isAscii = true; + + return $this; + } + + public function __toString(): string + { + return 'alpha_dash'.($this->isAscii ? ':ascii' : ''); + } +} diff --git a/src/Illuminate/Validation/Rules/AlphaNum.php b/src/Illuminate/Validation/Rules/AlphaNum.php new file mode 100644 index 000000000000..7a750a16b144 --- /dev/null +++ b/src/Illuminate/Validation/Rules/AlphaNum.php @@ -0,0 +1,22 @@ +isAscii = true; + + return $this; + } + + public function __toString(): string + { + return 'alpha_num'.($this->isAscii ? ':ascii' : ''); + } +} diff --git a/src/Illuminate/Validation/Rules/ArrayRule.php b/src/Illuminate/Validation/Rules/Arr.php similarity index 96% rename from src/Illuminate/Validation/Rules/ArrayRule.php rename to src/Illuminate/Validation/Rules/Arr.php index 4ee9794653d8..b01d3392a6d1 100644 --- a/src/Illuminate/Validation/Rules/ArrayRule.php +++ b/src/Illuminate/Validation/Rules/Arr.php @@ -7,7 +7,7 @@ use function Illuminate\Support\enum_value; -class ArrayRule implements Stringable +class Arr implements Stringable { /** * The accepted keys. diff --git a/src/Illuminate/Validation/Rules/Between.php b/src/Illuminate/Validation/Rules/Between.php new file mode 100644 index 000000000000..a20bdc1827c6 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Between.php @@ -0,0 +1,19 @@ +min},{$this->max}"; + } +} diff --git a/src/Illuminate/Validation/Rules/Confirmed.php b/src/Illuminate/Validation/Rules/Confirmed.php new file mode 100644 index 000000000000..1c6b0b31fa1b --- /dev/null +++ b/src/Illuminate/Validation/Rules/Confirmed.php @@ -0,0 +1,22 @@ +confirmationField = $confirmationField; + + return $this; + } + + public function __toString(): string + { + return 'confirmed'.($this->confirmationField ? ":{$this->confirmationField}" : ''); + } +} diff --git a/src/Illuminate/Validation/Rules/CurrentPassword.php b/src/Illuminate/Validation/Rules/CurrentPassword.php new file mode 100644 index 000000000000..1cdddd99ee0f --- /dev/null +++ b/src/Illuminate/Validation/Rules/CurrentPassword.php @@ -0,0 +1,22 @@ +guard = $guard; + + return $this; + } + + public function __toString(): string + { + return 'current_password'.($this->guard ? ":{$this->guard}" : ''); + } +} diff --git a/src/Illuminate/Validation/Rules/Date.php b/src/Illuminate/Validation/Rules/Date.php index cec8894f630c..3d90828a9a35 100644 --- a/src/Illuminate/Validation/Rules/Date.php +++ b/src/Illuminate/Validation/Rules/Date.php @@ -112,6 +112,11 @@ public function betweenOrEqual(DateTimeInterface|string $from, DateTimeInterface return $this->afterOrEqual($from)->beforeOrEqual($to); } + public function equals(DateTimeInterface|string $date): static + { + return $this->addRule('date_equals:'.$this->formatDate($date)); + } + /** * Add custom rules to the validation rules array. */ diff --git a/src/Illuminate/Validation/Rules/Decimal.php b/src/Illuminate/Validation/Rules/Decimal.php new file mode 100644 index 000000000000..3edf53a5210c --- /dev/null +++ b/src/Illuminate/Validation/Rules/Decimal.php @@ -0,0 +1,27 @@ +maxPlaces) && $this->minPlaces > $this->maxPlaces) { + throw new InvalidArgumentException('The min places value cannot be greater than the max places value.'); + } + } + + public function __toString(): string + { + if (is_null($this->maxPlaces)) { + return "decimal:{$this->minPlaces}"; + } + + return "decimal:{$this->minPlaces},{$this->maxPlaces}"; + } +} diff --git a/src/Illuminate/Validation/Rules/DeclinedIf.php b/src/Illuminate/Validation/Rules/DeclinedIf.php new file mode 100644 index 000000000000..13d9bd7347a6 --- /dev/null +++ b/src/Illuminate/Validation/Rules/DeclinedIf.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/Different.php b/src/Illuminate/Validation/Rules/Different.php new file mode 100644 index 000000000000..07f74d635958 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Different.php @@ -0,0 +1,17 @@ +field}"; + } +} diff --git a/src/Illuminate/Validation/Rules/Digits.php b/src/Illuminate/Validation/Rules/Digits.php new file mode 100644 index 000000000000..adb9c4b65b17 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Digits.php @@ -0,0 +1,17 @@ +length}"; + } +} diff --git a/src/Illuminate/Validation/Rules/DigitsBetween.php b/src/Illuminate/Validation/Rules/DigitsBetween.php new file mode 100644 index 000000000000..660b604ecf43 --- /dev/null +++ b/src/Illuminate/Validation/Rules/DigitsBetween.php @@ -0,0 +1,19 @@ +min},{$this->max}"; + } +} diff --git a/src/Illuminate/Validation/Rules/Distinct.php b/src/Illuminate/Validation/Rules/Distinct.php new file mode 100644 index 000000000000..4780b31e5edf --- /dev/null +++ b/src/Illuminate/Validation/Rules/Distinct.php @@ -0,0 +1,33 @@ +option = 'strict'; + + return $this; + } + + public function ignoreCase(): static + { + $this->option = 'ignore_case'; + + return $this; + } + + public function __toString(): string + { + if ($this->option) { + return "distinct:{$this->option}"; + } + + return 'distinct'; + } +} diff --git a/src/Illuminate/Validation/Rules/DoesntEndWith.php b/src/Illuminate/Validation/Rules/DoesntEndWith.php new file mode 100644 index 000000000000..abf5a8b36fcc --- /dev/null +++ b/src/Illuminate/Validation/Rules/DoesntEndWith.php @@ -0,0 +1,17 @@ +values); + } +} diff --git a/src/Illuminate/Validation/Rules/DoesntStartWith.php b/src/Illuminate/Validation/Rules/DoesntStartWith.php new file mode 100644 index 000000000000..0d4801845fd0 --- /dev/null +++ b/src/Illuminate/Validation/Rules/DoesntStartWith.php @@ -0,0 +1,17 @@ +values); + } +} diff --git a/src/Illuminate/Validation/Rules/EndsWith.php b/src/Illuminate/Validation/Rules/EndsWith.php new file mode 100644 index 000000000000..6a6a5be90ba1 --- /dev/null +++ b/src/Illuminate/Validation/Rules/EndsWith.php @@ -0,0 +1,17 @@ +values); + } +} diff --git a/src/Illuminate/Validation/Rules/ExcludeUnless.php b/src/Illuminate/Validation/Rules/ExcludeUnless.php new file mode 100644 index 000000000000..d3e13e2f9b94 --- /dev/null +++ b/src/Illuminate/Validation/Rules/ExcludeUnless.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/ExcludeWith.php b/src/Illuminate/Validation/Rules/ExcludeWith.php new file mode 100644 index 000000000000..9dabf336110c --- /dev/null +++ b/src/Illuminate/Validation/Rules/ExcludeWith.php @@ -0,0 +1,17 @@ +anotherField}"; + } +} diff --git a/src/Illuminate/Validation/Rules/ExcludeWithout.php b/src/Illuminate/Validation/Rules/ExcludeWithout.php new file mode 100644 index 000000000000..e8697b471dfc --- /dev/null +++ b/src/Illuminate/Validation/Rules/ExcludeWithout.php @@ -0,0 +1,17 @@ +anotherField}"; + } +} diff --git a/src/Illuminate/Validation/Rules/Extensions.php b/src/Illuminate/Validation/Rules/Extensions.php new file mode 100644 index 000000000000..4b68ecac1590 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Extensions.php @@ -0,0 +1,17 @@ +extensions); + } +} diff --git a/src/Illuminate/Validation/Rules/GreaterThan.php b/src/Illuminate/Validation/Rules/GreaterThan.php new file mode 100644 index 000000000000..b750eb355e8f --- /dev/null +++ b/src/Illuminate/Validation/Rules/GreaterThan.php @@ -0,0 +1,17 @@ +value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/GreaterThanOrEqual.php b/src/Illuminate/Validation/Rules/GreaterThanOrEqual.php new file mode 100644 index 000000000000..49220d3816a9 --- /dev/null +++ b/src/Illuminate/Validation/Rules/GreaterThanOrEqual.php @@ -0,0 +1,17 @@ +value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/InArray.php b/src/Illuminate/Validation/Rules/InArray.php new file mode 100644 index 000000000000..28b78ded5fb7 --- /dev/null +++ b/src/Illuminate/Validation/Rules/InArray.php @@ -0,0 +1,17 @@ +otherField}"; + } +} diff --git a/src/Illuminate/Validation/Rules/InArrayKeys.php b/src/Illuminate/Validation/Rules/InArrayKeys.php new file mode 100644 index 000000000000..08d94b23bc71 --- /dev/null +++ b/src/Illuminate/Validation/Rules/InArrayKeys.php @@ -0,0 +1,17 @@ +keys); + } +} diff --git a/src/Illuminate/Validation/Rules/IpAddress.php b/src/Illuminate/Validation/Rules/IpAddress.php new file mode 100644 index 000000000000..1e21600ec24b --- /dev/null +++ b/src/Illuminate/Validation/Rules/IpAddress.php @@ -0,0 +1,37 @@ +allowedVersions)) { + throw new InvalidArgumentException(sprintf( + 'The provided IP version %d is invalid. Please use one of these: %s', + $version, + implode(', ', $this->allowedVersions), + )); + } + + $this->version = $version; + + return $this; + } + + public function __toString(): string + { + return $this->version === null ? 'ip' : "ipv{$this->version}"; + } +} diff --git a/src/Illuminate/Validation/Rules/LessThan.php b/src/Illuminate/Validation/Rules/LessThan.php new file mode 100644 index 000000000000..3af039df1ca8 --- /dev/null +++ b/src/Illuminate/Validation/Rules/LessThan.php @@ -0,0 +1,17 @@ +value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/LessThanOrEqual.php b/src/Illuminate/Validation/Rules/LessThanOrEqual.php new file mode 100644 index 000000000000..76da1a4e8e46 --- /dev/null +++ b/src/Illuminate/Validation/Rules/LessThanOrEqual.php @@ -0,0 +1,17 @@ +value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/Max.php b/src/Illuminate/Validation/Rules/Max.php new file mode 100644 index 000000000000..8c7e13124fdb --- /dev/null +++ b/src/Illuminate/Validation/Rules/Max.php @@ -0,0 +1,43 @@ +value = $value; + } else { + throw new InvalidArgumentException(sprintf( + 'The provided value must be a callable or an integer, %s given.', + get_debug_type($value), + )); + } + } + + public function __toString(): string + { + if (is_callable($this->value)) { + $this->value = call_user_func($this->value); + } + + return "max:{$this->value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/MaxDigits.php b/src/Illuminate/Validation/Rules/MaxDigits.php new file mode 100644 index 000000000000..84f02cda1ef4 --- /dev/null +++ b/src/Illuminate/Validation/Rules/MaxDigits.php @@ -0,0 +1,17 @@ +value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/MimeTypes.php b/src/Illuminate/Validation/Rules/MimeTypes.php new file mode 100644 index 000000000000..e26994836bc0 --- /dev/null +++ b/src/Illuminate/Validation/Rules/MimeTypes.php @@ -0,0 +1,17 @@ +types); + } +} diff --git a/src/Illuminate/Validation/Rules/Mimes.php b/src/Illuminate/Validation/Rules/Mimes.php new file mode 100644 index 000000000000..2c39ce4d64bc --- /dev/null +++ b/src/Illuminate/Validation/Rules/Mimes.php @@ -0,0 +1,17 @@ +extensions); + } +} diff --git a/src/Illuminate/Validation/Rules/Min.php b/src/Illuminate/Validation/Rules/Min.php new file mode 100644 index 000000000000..1ed7e2878ee7 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Min.php @@ -0,0 +1,43 @@ +value = $value; + } else { + throw new InvalidArgumentException(sprintf( + 'The provided value must be a callable or an integer, %s given.', + get_debug_type($value), + )); + } + } + + public function __toString(): string + { + if (is_callable($this->value)) { + $this->value = call_user_func($this->value); + } + + return "min:{$this->value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/MinDigits.php b/src/Illuminate/Validation/Rules/MinDigits.php new file mode 100644 index 000000000000..4990fe5e81f6 --- /dev/null +++ b/src/Illuminate/Validation/Rules/MinDigits.php @@ -0,0 +1,17 @@ +value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/MissingIf.php b/src/Illuminate/Validation/Rules/MissingIf.php new file mode 100644 index 000000000000..070644841695 --- /dev/null +++ b/src/Illuminate/Validation/Rules/MissingIf.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/MissingUnless.php b/src/Illuminate/Validation/Rules/MissingUnless.php new file mode 100644 index 000000000000..3823cc64df7a --- /dev/null +++ b/src/Illuminate/Validation/Rules/MissingUnless.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/MissingWith.php b/src/Illuminate/Validation/Rules/MissingWith.php new file mode 100644 index 000000000000..724717758101 --- /dev/null +++ b/src/Illuminate/Validation/Rules/MissingWith.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/MissingWithAll.php b/src/Illuminate/Validation/Rules/MissingWithAll.php new file mode 100644 index 000000000000..31bafcaf8dab --- /dev/null +++ b/src/Illuminate/Validation/Rules/MissingWithAll.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/MultipleOf.php b/src/Illuminate/Validation/Rules/MultipleOf.php new file mode 100644 index 000000000000..6872d715b543 --- /dev/null +++ b/src/Illuminate/Validation/Rules/MultipleOf.php @@ -0,0 +1,17 @@ +value; + } +} diff --git a/src/Illuminate/Validation/Rules/NotRegex.php b/src/Illuminate/Validation/Rules/NotRegex.php new file mode 100644 index 000000000000..a044b650015d --- /dev/null +++ b/src/Illuminate/Validation/Rules/NotRegex.php @@ -0,0 +1,17 @@ +pattern}"; + } +} diff --git a/src/Illuminate/Validation/Rules/PresentIf.php b/src/Illuminate/Validation/Rules/PresentIf.php new file mode 100644 index 000000000000..3cd8674b70fe --- /dev/null +++ b/src/Illuminate/Validation/Rules/PresentIf.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/PresentUnless.php b/src/Illuminate/Validation/Rules/PresentUnless.php new file mode 100644 index 000000000000..3ce4f0635259 --- /dev/null +++ b/src/Illuminate/Validation/Rules/PresentUnless.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/PresentWith.php b/src/Illuminate/Validation/Rules/PresentWith.php new file mode 100644 index 000000000000..9c2290b2cae5 --- /dev/null +++ b/src/Illuminate/Validation/Rules/PresentWith.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/PresentWithAll.php b/src/Illuminate/Validation/Rules/PresentWithAll.php new file mode 100644 index 000000000000..dc6474740ffc --- /dev/null +++ b/src/Illuminate/Validation/Rules/PresentWithAll.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/ProhibitedIfAccepted.php b/src/Illuminate/Validation/Rules/ProhibitedIfAccepted.php new file mode 100644 index 000000000000..3eefcad1f33d --- /dev/null +++ b/src/Illuminate/Validation/Rules/ProhibitedIfAccepted.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/ProhibitedIfDeclined.php b/src/Illuminate/Validation/Rules/ProhibitedIfDeclined.php new file mode 100644 index 000000000000..b0ea7c79ae31 --- /dev/null +++ b/src/Illuminate/Validation/Rules/ProhibitedIfDeclined.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/ProhibitedUnless.php b/src/Illuminate/Validation/Rules/ProhibitedUnless.php new file mode 100644 index 000000000000..f5cf4ec468b6 --- /dev/null +++ b/src/Illuminate/Validation/Rules/ProhibitedUnless.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/Prohibits.php b/src/Illuminate/Validation/Rules/Prohibits.php new file mode 100644 index 000000000000..cb96387461b3 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Prohibits.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/Regex.php b/src/Illuminate/Validation/Rules/Regex.php new file mode 100644 index 000000000000..3ca6c02a1f62 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Regex.php @@ -0,0 +1,17 @@ +pattern}"; + } +} diff --git a/src/Illuminate/Validation/Rules/RequiredArrayKeys.php b/src/Illuminate/Validation/Rules/RequiredArrayKeys.php new file mode 100644 index 000000000000..7651b37d23fc --- /dev/null +++ b/src/Illuminate/Validation/Rules/RequiredArrayKeys.php @@ -0,0 +1,17 @@ +keys); + } +} diff --git a/src/Illuminate/Validation/Rules/RequiredIfAccepted.php b/src/Illuminate/Validation/Rules/RequiredIfAccepted.php new file mode 100644 index 000000000000..03555439de0a --- /dev/null +++ b/src/Illuminate/Validation/Rules/RequiredIfAccepted.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/RequiredIfDeclined.php b/src/Illuminate/Validation/Rules/RequiredIfDeclined.php new file mode 100644 index 000000000000..7edbe0647134 --- /dev/null +++ b/src/Illuminate/Validation/Rules/RequiredIfDeclined.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/RequiredUnless.php b/src/Illuminate/Validation/Rules/RequiredUnless.php new file mode 100644 index 000000000000..3adaca64dbda --- /dev/null +++ b/src/Illuminate/Validation/Rules/RequiredUnless.php @@ -0,0 +1,19 @@ +anotherField.','.($this->value ?? 'null'); + } +} diff --git a/src/Illuminate/Validation/Rules/RequiredWith.php b/src/Illuminate/Validation/Rules/RequiredWith.php new file mode 100644 index 000000000000..e29550f72dd5 --- /dev/null +++ b/src/Illuminate/Validation/Rules/RequiredWith.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/RequiredWithAll.php b/src/Illuminate/Validation/Rules/RequiredWithAll.php new file mode 100644 index 000000000000..06581c61fb12 --- /dev/null +++ b/src/Illuminate/Validation/Rules/RequiredWithAll.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/RequiredWithout.php b/src/Illuminate/Validation/Rules/RequiredWithout.php new file mode 100644 index 000000000000..315184ea8674 --- /dev/null +++ b/src/Illuminate/Validation/Rules/RequiredWithout.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/RequiredWithoutAll.php b/src/Illuminate/Validation/Rules/RequiredWithoutAll.php new file mode 100644 index 000000000000..ea5429bcb6ac --- /dev/null +++ b/src/Illuminate/Validation/Rules/RequiredWithoutAll.php @@ -0,0 +1,17 @@ +fields); + } +} diff --git a/src/Illuminate/Validation/Rules/Same.php b/src/Illuminate/Validation/Rules/Same.php new file mode 100644 index 000000000000..2fcfeae52a63 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Same.php @@ -0,0 +1,17 @@ +field}"; + } +} diff --git a/src/Illuminate/Validation/Rules/Size.php b/src/Illuminate/Validation/Rules/Size.php new file mode 100644 index 000000000000..cfbae47a96a2 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Size.php @@ -0,0 +1,17 @@ +value}"; + } +} diff --git a/src/Illuminate/Validation/Rules/StartsWith.php b/src/Illuminate/Validation/Rules/StartsWith.php new file mode 100644 index 000000000000..348409238919 --- /dev/null +++ b/src/Illuminate/Validation/Rules/StartsWith.php @@ -0,0 +1,17 @@ +values); + } +} diff --git a/src/Illuminate/Validation/Rules/Timezone.php b/src/Illuminate/Validation/Rules/Timezone.php new file mode 100644 index 000000000000..fa2cc99b1ccd --- /dev/null +++ b/src/Illuminate/Validation/Rules/Timezone.php @@ -0,0 +1,17 @@ +arguments ? ':'.implode(',', $this->arguments) : ''); + } +} diff --git a/src/Illuminate/Validation/Rules/Url.php b/src/Illuminate/Validation/Rules/Url.php new file mode 100644 index 000000000000..3d522f9bd811 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Url.php @@ -0,0 +1,28 @@ +protocols = $protocols; + + return $this; + } + + public function __toString(): string + { + return 'url'.($this->protocols ? ':'.implode(',', $this->protocols) : ''); + } +} diff --git a/src/Illuminate/Validation/Rules/Uuid.php b/src/Illuminate/Validation/Rules/Uuid.php new file mode 100644 index 000000000000..5d0bb12eee67 --- /dev/null +++ b/src/Illuminate/Validation/Rules/Uuid.php @@ -0,0 +1,22 @@ +version = $version; + + return $this; + } + + public function __toString(): string + { + return 'uuid'.($this->version ? ':'.$this->version : ''); + } +} diff --git a/tests/Validation/ValidationArrayRuleTest.php b/tests/Validation/ValidationArrRuleTest.php similarity index 98% rename from tests/Validation/ValidationArrayRuleTest.php rename to tests/Validation/ValidationArrRuleTest.php index 1057faa7adf1..d9896af1dadf 100644 --- a/tests/Validation/ValidationArrayRuleTest.php +++ b/tests/Validation/ValidationArrRuleTest.php @@ -10,7 +10,7 @@ include_once 'Enums.php'; -class ValidationArrayRuleTest extends TestCase +class ValidationArrRuleTest extends TestCase { public function testItCorrectlyFormatsAStringVersionOfTheRule() { diff --git a/tests/Validation/ValidationRuleBuilderMethodTest.php b/tests/Validation/ValidationRuleBuilderMethodTest.php new file mode 100644 index 000000000000..8b9a14573a70 --- /dev/null +++ b/tests/Validation/ValidationRuleBuilderMethodTest.php @@ -0,0 +1,525 @@ +assertSame(Rule::alpha()->__toString(), 'alpha'); + $this->assertSame(Rule::alpha()->ascii()->__toString(), 'alpha:ascii'); + } + + public function testAlphaDashRule() + { + $this->assertSame(Rule::alphaDash()->__toString(), 'alpha_dash'); + $this->assertSame(Rule::alphaDash()->ascii()->__toString(), 'alpha_dash:ascii'); + } + + public function testAlphaNumRule() + { + $this->assertSame(Rule::alphaNum()->__toString(), 'alpha_num'); + $this->assertSame(Rule::alphaNum()->ascii()->__toString(), 'alpha_num:ascii'); + } + + public function testAsciiRule() + { + $this->assertSame(Rule::ascii(), 'ascii'); + } + + public function testConfirmedRule() + { + $this->assertSame(Rule::confirmed()->__toString(), 'confirmed'); + $this->assertSame(Rule::confirmed()->customField('foo')->__toString(), 'confirmed:foo'); + } + + public function testCurrentPasswordRule() + { + $this->assertSame(Rule::currentPassword()->__toString(), 'current_password'); + $this->assertSame('current_password:api', Rule::currentPassword()->guard('api')->__toString()); + } + + public function testDifferentRule() + { + $this->assertSame(Rule::different('email')->__toString(), 'different:email'); + } + + public function testSizeRule() + { + $this->assertSame(Rule::size(12)->__toString(), 'size:12'); + $this->assertSame(Rule::size(12.56)->__toString(), 'size:12.56'); + } + + public function testSameRule() + { + $this->assertSame(Rule::same('field')->__toString(), 'same:field'); + } + + public function testCurrentPasswordRuleWithCustomGuard() + { + $this->assertSame(Rule::currentPassword()->guard('api')->__toString(), 'current_password:api'); + } + + public function testActiveUrlRule() + { + $this->assertSame(Rule::activeUrl(), 'active_url'); + } + + public function testAcceptedIfRule() + { + $this->assertSame(Rule::acceptedIf('user', null)->__toString(), 'accepted_if:user,null'); + $this->assertSame(Rule::acceptedIf('user', 24)->__toString(), 'accepted_if:user,24'); + $this->assertSame(Rule::acceptedIf('user', 24.56)->__toString(), 'accepted_if:user,24.56'); + $this->assertSame(Rule::acceptedIf('user', 'foo')->__toString(), 'accepted_if:user,foo'); + } + + public function testDeclinedRule() + { + $this->assertSame(Rule::declined(), 'declined'); + } + + public function testDoesntStartWithRule() + { + $this->assertSame(Rule::doesntStartWith(['foo'])->__toString(), 'doesnt_start_with:foo'); + $this->assertSame(Rule::doesntStartWith(['foo', 'bar'])->__toString(), 'doesnt_start_with:foo,bar'); + } + + public function testStartsWithRule() + { + $this->assertSame(Rule::startsWith(['foo'])->__toString(), 'starts_with:foo'); + $this->assertSame(Rule::startsWith(['foo', 'bar'])->__toString(), 'starts_with:foo,bar'); + } + + public function testIpRule() + { + $this->assertSame(Rule::ip()->__toString(), 'ip'); + $this->assertSame(Rule::ip()->version(4)->__toString(), 'ipv4'); + $this->assertSame(Rule::ip()->version(6)->__toString(), 'ipv6'); + + $this->expectException(InvalidArgumentException::class); + $this->assertSame(Rule::ip()->version(1)->__toString(), 'ipv4'); + } + + public function testUuidRule() + { + $this->assertSame(Rule::uuid()->__toString(), 'uuid'); + $this->assertSame(Rule::uuid()->version(3)->__toString(), 'uuid:3'); + } + + public function testDoesntEndWithRule() + { + $this->assertSame(Rule::doesntEndWith(['foo'])->__toString(), 'doesnt_end_with:foo'); + $this->assertSame(Rule::doesntEndWith(['foo', 'bar'])->__toString(), 'doesnt_end_with:foo,bar'); + } + + public function testJsonRule() + { + $this->assertSame(Rule::json(), 'json'); + } + + public function testLowercaseRule() + { + $this->assertSame(Rule::lowercase(), 'lowercase'); + } + + public function testUppercaseRule() + { + $this->assertSame(Rule::uppercase(), 'uppercase'); + } + + public function testUlidRule() + { + $this->assertSame(Rule::ulid(), 'ulid'); + } + + public function testEndsWithRule() + { + $this->assertSame(Rule::endsWith(['foo'])->__toString(), 'ends_with:foo'); + $this->assertSame(Rule::endsWith(['foo', 'bar'])->__toString(), 'ends_with:foo,bar'); + } + + public function testHexColorRule() + { + $this->assertSame(Rule::hexColor(), 'hex_color'); + } + + public function testDeclinedIfRule() + { + $this->assertSame(Rule::declinedIf('user', null)->__toString(), 'declined_if:user,null'); + $this->assertSame(Rule::declinedIf('user', 24)->__toString(), 'declined_if:user,24'); + $this->assertSame(Rule::declinedIf('user', 24.56)->__toString(), 'declined_if:user,24.56'); + $this->assertSame(Rule::declinedIf('user', 'foo')->__toString(), 'declined_if:user,foo'); + } + + public function testBooleanRule() + { + $this->assertSame(Rule::boolean(), 'boolean'); + } + + public function testStringRule() + { + $this->assertSame(Rule::string(), 'string'); + } + + public function testAcceptedRule() + { + $this->assertSame(Rule::accepted(), 'accepted'); + } + + public function testRequiredRule() + { + $this->assertSame(Rule::required(), 'required'); + } + + public function testIntegerRule() + { + $this->assertSame(Rule::integer(), 'integer'); + } + + public function testNullableRule() + { + $this->assertSame(Rule::nullable(), 'nullable'); + } + + public function testDecimalRule() + { + $this->assertSame(Rule::decimal(minPlaces: 2)->__toString(), 'decimal:2'); + $this->assertSame(Rule::decimal(minPlaces: 2, maxPlaces: 5)->__toString(), 'decimal:2,5'); + + $this->expectException(InvalidArgumentException::class); + Rule::decimal(minPlaces: 5, maxPlaces: 2); + } + + public function testSometimesRule() + { + $this->assertSame(Rule::sometimes(), 'sometimes'); + } + + public function testUrlRule() + { + $this->assertSame(Rule::url()->__toString(), 'url'); + $this->assertSame(Rule::url()->protocols(['http', 'https'])->__toString(), 'url:http,https'); + } + + public function testMacAddressRule() + { + $this->assertSame(Rule::macAddress(), 'mac_address'); + } + + public function testRegexRule() + { + $this->assertSame(Rule::regex('/^.+@.+$/i')->__toString(), 'regex:/^.+@.+$/i'); + } + + public function testNotRegexRule() + { + $this->assertSame(Rule::notRegex('/^.+@.+$/i')->__toString(), 'not_regex:/^.+@.+$/i'); + } + + public function testMinRule() + { + $this->assertSame(Rule::min(12)->__toString(), 'min:12'); + $this->assertSame(Rule::min(fn (): int => 12)->__toString(), 'min:12'); + } + + public function testMaxRule() + { + $this->assertSame(Rule::max(12)->__toString(), 'max:12'); + $this->assertSame(Rule::max(fn (): int => 12)->__toString(), 'max:12'); + } + + public function testBetweenRule() + { + $this->assertSame(Rule::between(1, 10)->__toString(), 'between:1,10'); + $this->assertSame(Rule::between(0.00, 0.99)->__toString(), 'between:0,0.99'); + $this->assertSame(Rule::between(1.11, 1.99)->__toString(), 'between:1.11,1.99'); + } + + public function testExtensionsRule() + { + $this->assertSame(Rule::extensions(['png', 'mp3'])->__toString(), 'extensions:png,mp3'); + } + + public function testDigitsRule() + { + $this->assertSame(Rule::digits(12)->__toString(), 'digits:12'); + } + + public function testDigitsBetweenRule() + { + $this->assertSame(Rule::digitsBetween(12, 24)->__toString(), 'digits_between:12,24'); + } + + public function testMaxDigitsRule() + { + $this->assertSame(Rule::maxDigits(3)->__toString(), 'max_digits:3'); + } + + public function testMinDigitsRule() + { + $this->assertSame(Rule::minDigits(3)->__toString(), 'min_digits:3'); + } + + public function testDistinctRule() + { + $this->assertSame(Rule::distinct()->__toString(), 'distinct'); + $this->assertSame(Rule::distinct()->ignoreCase()->__toString(), 'distinct:ignore_case'); + $this->assertSame(Rule::distinct()->strict()->__toString(), 'distinct:strict'); + } + + public function testGreaterThanRule() + { + $this->assertSame(Rule::greaterThan(1)->__toString(), 'gt:1'); + $this->assertSame(Rule::greaterThan('item')->__toString(), 'gt:item'); + + $this->assertSame(Rule::gt(1)->__toString(), 'gt:1'); + $this->assertSame(Rule::gt('item')->__toString(), 'gt:item'); + } + + public function testGreaterThanOrEqualRule() + { + $this->assertSame(Rule::greaterThanOrEqual(1)->__toString(), 'gte:1'); + $this->assertSame(Rule::greaterThanOrEqual('item')->__toString(), 'gte:item'); + + $this->assertSame(Rule::gte(1)->__toString(), 'gte:1'); + $this->assertSame(Rule::gte('item')->__toString(), 'gte:item'); + } + + public function testLessThanRule() + { + $this->assertSame(Rule::lessThan(1)->__toString(), 'lt:1'); + $this->assertSame(Rule::lessThan('item')->__toString(), 'lt:item'); + + $this->assertSame(Rule::lt(1)->__toString(), 'lt:1'); + $this->assertSame(Rule::lt('item')->__toString(), 'lt:item'); + } + + public function testLessThanOrEqualRule() + { + $this->assertSame(Rule::lessThanOrEqual(1)->__toString(), 'lte:1'); + $this->assertSame(Rule::lessThanOrEqual('item')->__toString(), 'lte:item'); + + $this->assertSame(Rule::lte(1)->__toString(), 'lte:1'); + $this->assertSame(Rule::lte('item')->__toString(), 'lte:item'); + } + + public function testMultipleOfRule() + { + $this->assertSame(Rule::multipleOf(5)->__toString(), 'multiple_of:5'); + $this->assertSame(Rule::multipleOf(0.25)->__toString(), 'multiple_of:0.25'); + } + + public function testInArrayRule() + { + $this->assertSame(Rule::inArray('foo')->__toString(), 'in_array:foo'); + } + + public function testInArrayKeysRule() + { + $this->assertSame(Rule::inArrayKeys(['foo', 'bar'])->__toString(), 'in_array_keys:foo,bar'); + } + + public function testListRule() + { + $this->assertSame(Rule::list(), 'list'); + } + + public function testBailRule() + { + $this->assertSame(Rule::bail(), 'bail'); + } + + public function testPresentRule() + { + $this->assertSame(Rule::present(), 'present'); + } + + public function testProhibitedRule() + { + $this->assertSame(Rule::prohibited(), 'prohibited'); + } + + public function testFilledRule() + { + $this->assertSame(Rule::filled(), 'filled'); + } + + public function testDateEqualsRule() + { + $now = now()->toImmutable(); + + $this->assertSame(Rule::date()->equals('now')->__toString(), 'date|date_equals:now'); + $this->assertSame(Rule::date()->equals('tomorrow')->__toString(), 'date|date_equals:tomorrow'); + $this->assertSame(Rule::date()->equals($now)->__toString(), 'date|date_equals:'.$now->format('Y-m-d')); + $this->assertSame(Rule::date()->equals($now->format('H:i'))->__toString(), 'date|date_equals:'.$now->format('H:i')); + } + + public function testTimezoneRule() + { + $this->assertSame(Rule::timezone()->__toString(), 'timezone'); + $this->assertSame(Rule::timezone(['Africa'])->__toString(), 'timezone:Africa'); + $this->assertSame(Rule::timezone(['per_country', 'US'])->__toString(), 'timezone:per_country,US'); + } + + public function testExcludeRule() + { + $this->assertSame(Rule::exclude(), 'exclude'); + } + + public function testMimeTypesRule() + { + $this->assertSame(Rule::mimeTypes(['video/avi', 'video/mpeg', 'video/quicktime'])->__toString(), 'mimetypes:video/avi,video/mpeg,video/quicktime'); + } + + public function testMimesRule() + { + $this->assertSame(Rule::mimes(['jpg', 'bmp', 'png'])->__toString(), 'mimes:jpg,bmp,png'); + } + + public function testExcludeUnlessRule() + { + $this->assertSame(Rule::excludeUnless('user', null)->__toString(), 'exclude_unless:user,null'); + $this->assertSame(Rule::excludeUnless('user', 24)->__toString(), 'exclude_unless:user,24'); + $this->assertSame(Rule::excludeUnless('user', 24.56)->__toString(), 'exclude_unless:user,24.56'); + $this->assertSame(Rule::excludeUnless('user', 'foo')->__toString(), 'exclude_unless:user,foo'); + } + + public function testExcludeWithRule() + { + $this->assertSame(Rule::excludeWith('foo')->__toString(), 'exclude_with:foo'); + } + + public function testExcludeWithoutRule() + { + $this->assertSame(Rule::excludeWithout('foo')->__toString(), 'exclude_without:foo'); + } + + public function testMissingRule() + { + $this->assertSame(Rule::missing(), 'missing'); + } + + public function testProhibitsRule() + { + $this->assertSame(Rule::prohibits(['foo', 'bar'])->__toString(), 'prohibits:foo,bar'); + } + + public function testMissingIfRule() + { + $this->assertSame(Rule::missingIf('user', null)->__toString(), 'missing_if:user,null'); + $this->assertSame(Rule::missingIf('user', 24)->__toString(), 'missing_if:user,24'); + $this->assertSame(Rule::missingIf('user', 24.56)->__toString(), 'missing_if:user,24.56'); + $this->assertSame(Rule::missingIf('user', 'foo')->__toString(), 'missing_if:user,foo'); + } + + public function testRequiredArrayKeysRule() + { + $this->assertSame(Rule::requiredArrayKeys(['foo', 'bar'])->__toString(), 'required_array_keys:foo,bar'); + } + + public function testMissingUnlessRule() + { + $this->assertSame(Rule::missingUnless('user', null)->__toString(), 'missing_unless:user,null'); + $this->assertSame(Rule::missingUnless('user', 24)->__toString(), 'missing_unless:user,24'); + $this->assertSame(Rule::missingUnless('user', 24.56)->__toString(), 'missing_unless:user,24.56'); + $this->assertSame(Rule::missingUnless('user', 'foo')->__toString(), 'missing_unless:user,foo'); + } + + public function testPresentIfRule() + { + $this->assertSame(Rule::presentIf('user', null)->__toString(), 'present_if:user,null'); + $this->assertSame(Rule::presentIf('user', 24)->__toString(), 'present_if:user,24'); + $this->assertSame(Rule::presentIf('user', 24.56)->__toString(), 'present_if:user,24.56'); + $this->assertSame(Rule::presentIf('user', 'foo')->__toString(), 'present_if:user,foo'); + } + + public function testProhibitedUnlessRule() + { + $this->assertSame(Rule::prohibitedUnless('user', null)->__toString(), 'prohibited_unless:user,null'); + $this->assertSame(Rule::prohibitedUnless('user', 24)->__toString(), 'prohibited_unless:user,24'); + $this->assertSame(Rule::prohibitedUnless('user', 24.56)->__toString(), 'prohibited_unless:user,24.56'); + $this->assertSame(Rule::prohibitedUnless('user', 'foo')->__toString(), 'prohibited_unless:user,foo'); + } + + public function testRequiredUnlessRule() + { + $this->assertSame(Rule::requiredUnless('user', null)->__toString(), 'required_unless:user,null'); + $this->assertSame(Rule::requiredUnless('user', 24)->__toString(), 'required_unless:user,24'); + $this->assertSame(Rule::requiredUnless('user', 24.56)->__toString(), 'required_unless:user,24.56'); + $this->assertSame(Rule::requiredUnless('user', 'foo')->__toString(), 'required_unless:user,foo'); + } + + public function testMissingWithRule() + { + $this->assertSame(Rule::missingWith(['foo', 'bar'])->__toString(), 'missing_with:foo,bar'); + } + + public function testMissingWithAllRule() + { + $this->assertSame(Rule::missingWithAll(['foo', 'bar'])->__toString(), 'missing_with_all:foo,bar'); + } + + public function testPresentUnlessRule() + { + $this->assertSame(Rule::presentUnless('user', null)->__toString(), 'present_unless:user,null'); + $this->assertSame(Rule::presentUnless('user', 24)->__toString(), 'present_unless:user,24'); + $this->assertSame(Rule::presentUnless('user', 24.56)->__toString(), 'present_unless:user,24.56'); + $this->assertSame(Rule::presentUnless('user', 'foo')->__toString(), 'present_unless:user,foo'); + } + + public function testPresentWithRule() + { + $this->assertSame(Rule::presentWith(['foo', 'bar'])->__toString(), 'present_with:foo,bar'); + } + + public function testPresentWithAllRule() + { + $this->assertSame(Rule::presentWithAll(['foo', 'bar'])->__toString(), 'present_with_all:foo,bar'); + } + + public function testRequiredWithRule() + { + $this->assertSame(Rule::requiredWith(['foo', 'bar'])->__toString(), 'required_with:foo,bar'); + } + + public function testRequiredWithAllRule() + { + $this->assertSame(Rule::requiredWithAll(['foo', 'bar'])->__toString(), 'required_with_all:foo,bar'); + } + + public function testRequiredWithoutRule() + { + $this->assertSame(Rule::requiredWithout(['foo', 'bar'])->__toString(), 'required_without:foo,bar'); + } + + public function testRequiredWithoutAllRule() + { + $this->assertSame(Rule::requiredWithoutAll(['foo', 'bar'])->__toString(), 'required_without_all:foo,bar'); + } + + public function testProhibitedIfAcceptedRule() + { + $this->assertSame(Rule::prohibitedIfAccepted(['foo', 'bar'])->__toString(), 'prohibited_if_accepted:foo,bar'); + } + + public function testProhibitedIfDeclinedRule() + { + $this->assertSame(Rule::prohibitedIfDeclined(['foo', 'bar'])->__toString(), 'prohibited_if_declined:foo,bar'); + } + + public function testRequiredIfAcceptedRule() + { + $this->assertSame(Rule::requiredIfAccepted(['foo', 'bar'])->__toString(), 'required_if_accepted:foo,bar'); + } + + public function testRequiredIfDeclinedRule() + { + $this->assertSame(Rule::requiredIfDeclined(['foo', 'bar'])->__toString(), 'required_if_declined:foo,bar'); + } +}