Skip to content

Commit 47f8f82

Browse files
committed
Remove mathematical, niche and deprecated validators
This commit removes validators described in #1642, refactoring to clean up after their removal. - Url was refactored to use the function `filter_var` instead. - tests/bootstrap.php is no longer needed and was removed. - Updated migration guide with recommendations for replacements.
1 parent 7876576 commit 47f8f82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+56
-1830
lines changed

docs/migrating-from-v2-to-v3.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,39 @@ These validators have been replaced by `DateTimeDiff`, which provides more flexi
156156
+ v::dateTimeDiff('years', v::between(18, 65))->assert($birthDate);
157157
```
158158

159+
##### `PrimeNumber`, `Fibonacci`, `PerfectSquare`
160+
161+
Combine `Callback` with a mathematical library of your choice:
162+
163+
```diff
164+
- v::primeNumber()->assert(7);
165+
+ v::callback(static fn ($input) => \MathPHP\NumberTheory\Integer::isPrime($input))->assert(7);
166+
```
167+
168+
See: https://github.com/markrogoyski/math-php
169+
170+
##### `FilterVar`
171+
172+
Use `Callback` instead:
173+
174+
```diff
175+
- v::filterVar(FILTER_VALIDATE_INT)->assert(123);
176+
+ v::callback(static fn($input) => filter_var($input, FILTER_VALIDATE_INT) !== false)->assert(123);
177+
```
178+
179+
##### `Uploaded`
180+
181+
Use `Callback` instead:
182+
183+
```diff
184+
- v::uploaded()->assert($fileName);
185+
+ v::callback('is_uploaded_file')->assert($fileName);
186+
```
187+
188+
##### `VideoUrl`
189+
190+
We offer no recommendation for replacing this validator.
191+
159192
#### Behavior changes
160193

161194
##### `Attribute` replaced by `Property` variants

docs/validators.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ In this page you will find a list of validators by their category.
2525

2626
**Date and Time**: [Date][] - [DateTime][] - [DateTimeDiff][] - [LeapDate][] - [LeapYear][] - [Time][]
2727

28-
**File system**: [Directory][] - [Executable][] - [Exists][] - [Extension][] - [File][] - [Image][] - [Mimetype][] - [Readable][] - [Size][] - [SymbolicLink][] - [Uploaded][] - [Writable][]
28+
**File system**: [Directory][] - [Executable][] - [Exists][] - [Extension][] - [File][] - [Image][] - [Mimetype][] - [Readable][] - [Size][] - [SymbolicLink][] - [Writable][]
2929

3030
**ISO codes**: [CountryCode][] - [CurrencyCode][] - [LanguageCode][] - [SubdivisionCode][]
3131

3232
**Identifications**: [Bsn][] - [Cnh][] - [Cnpj][] - [Cpf][] - [Hetu][] - [Imei][] - [Isbn][] - [Luhn][] - [MacAddress][] - [NfeAccessKey][] - [Nif][] - [Nip][] - [Pesel][] - [Pis][] - [PolishIdCard][] - [PortugueseNif][]
3333

34-
**Internet**: [Domain][] - [Email][] - [Ip][] - [PublicDomainSuffix][] - [Tld][] - [Url][] - [VideoUrl][]
34+
**Internet**: [Domain][] - [Email][] - [Ip][] - [PublicDomainSuffix][] - [Tld][] - [Url][]
3535

3636
**Localization**: [CountryCode][] - [CurrencyCode][] - [LanguageCode][] - [PostalCode][] - [SubdivisionCode][]
3737

38-
**Math**: [Factor][] - [Fibonacci][] - [Finite][] - [Infinite][] - [Multiple][] - [Negative][] - [PerfectSquare][] - [Positive][] - [PrimeNumber][]
38+
**Math**: [Factor][] - [Finite][] - [Infinite][] - [Multiple][] - [Negative][] - [Positive][]
3939

40-
**Miscellaneous**: [Blank][] - [Falsy][] - [FilterVar][] - [Named][] - [Templated][] - [Undef][]
40+
**Miscellaneous**: [Blank][] - [Falsy][] - [Named][] - [Templated][] - [Undef][]
4141

4242
**Nesting**: [AllOf][] - [AnyOf][] - [Call][] - [Circuit][] - [Each][] - [Key][] - [KeySet][] - [Lazy][] - [NoneOf][] - [Not][] - [NullOr][] - [OneOf][] - [Property][] - [PropertyOptional][] - [UndefOr][] - [When][]
4343

44-
**Numbers**: [Base][] - [Decimal][] - [Digit][] - [Even][] - [Factor][] - [Fibonacci][] - [Finite][] - [FloatType][] - [FloatVal][] - [Infinite][] - [IntType][] - [IntVal][] - [Multiple][] - [Negative][] - [Number][] - [NumericVal][] - [Odd][] - [PerfectSquare][] - [Positive][] - [PrimeNumber][] - [Roman][]
44+
**Numbers**: [Base][] - [Decimal][] - [Digit][] - [Even][] - [Factor][] - [Finite][] - [FloatType][] - [FloatVal][] - [Infinite][] - [IntType][] - [IntVal][] - [Multiple][] - [Negative][] - [Number][] - [NumericVal][] - [Odd][] - [Positive][] - [Roman][]
4545

4646
**Objects**: [Attributes][] - [Instance][] - [ObjectType][] - [Property][] - [PropertyExists][] - [PropertyOptional][]
4747

48-
**Strings**: [Alnum][] - [Alpha][] - [Base64][] - [Charset][] - [Consonant][] - [Contains][] - [ContainsAny][] - [ContainsCount][] - [Control][] - [Digit][] - [Emoji][] - [EndsWith][] - [Graph][] - [HexRgbColor][] - [In][] - [Json][] - [Lowercase][] - [Phone][] - [PhpLabel][] - [PostalCode][] - [Printable][] - [Punct][] - [Regex][] - [Slug][] - [Sorted][] - [Space][] - [Spaced][] - [StartsWith][] - [StringType][] - [StringVal][] - [Uppercase][] - [Uuid][] - [Version][] - [Vowel][] - [Xdigit][]
48+
**Strings**: [Alnum][] - [Alpha][] - [Base64][] - [Charset][] - [Consonant][] - [Contains][] - [ContainsAny][] - [ContainsCount][] - [Control][] - [Digit][] - [Emoji][] - [EndsWith][] - [Graph][] - [HexRgbColor][] - [In][] - [Json][] - [Lowercase][] - [Phone][] - [PostalCode][] - [Printable][] - [Punct][] - [Regex][] - [Slug][] - [Sorted][] - [Space][] - [Spaced][] - [StartsWith][] - [StringType][] - [StringVal][] - [Uppercase][] - [Uuid][] - [Version][] - [Vowel][] - [Xdigit][]
4949

5050
**Structures**: [Attributes][] - [Key][] - [KeyExists][] - [KeyOptional][] - [KeySet][] - [Named][] - [Property][] - [PropertyExists][] - [PropertyOptional][] - [Templated][]
5151

@@ -110,9 +110,7 @@ In this page you will find a list of validators by their category.
110110
- [Factor][] - `v::factor(0)->assert(5);`
111111
- [FalseVal][] - `v::falseVal()->assert(false);`
112112
- [Falsy][] - `v::falsy()->assert('');`
113-
- [Fibonacci][] - `v::fibonacci()->assert(1);`
114113
- [File][] - `v::file()->assert(__FILE__);`
115-
- [FilterVar][] - `v::filterVar(FILTER_VALIDATE_EMAIL)->assert('bob@example.com');`
116114
- [Finite][] - `v::finite()->assert('10');`
117115
- [FloatType][] - `v::floatType()->assert(1.5);`
118116
- [FloatVal][] - `v::floatVal()->assert(1.5);`
@@ -167,16 +165,13 @@ In this page you will find a list of validators by their category.
167165
- [ObjectType][] - `v::objectType()->assert(new stdClass);`
168166
- [Odd][] - `v::odd()->assert(3);`
169167
- [OneOf][] - `v::oneOf(v::digit(), v::alpha())->assert('AB');`
170-
- [PerfectSquare][] - `v::perfectSquare()->assert(25); // (5*5)`
171168
- [Pesel][] - `v::pesel()->assert('21120209256');`
172169
- [Phone][] - `v::phone()->assert('+1 650 253 00 00');`
173-
- [PhpLabel][] - `v::phpLabel()->assert('person'); //true`
174170
- [Pis][] - `v::pis()->assert('120.0340.678-8');`
175171
- [PolishIdCard][] - `v::polishIdCard()->assert('AYW036733');`
176172
- [PortugueseNif][] - `v::portugueseNif()->assert('124885446');`
177173
- [Positive][] - `v::positive()->assert(1);`
178174
- [PostalCode][] - `v::postalCode('BR')->assert('02179000');`
179-
- [PrimeNumber][] - `v::primeNumber()->assert(7);`
180175
- [Printable][] - `v::printable()->assert('LMKA0$% _123');`
181176
- [Property][] - `v::property('name', v::equals('The Respect Panda'))->assert($object);`
182177
- [PropertyExists][] - `v::propertyExists('name')->assert($object);`
@@ -206,12 +201,10 @@ In this page you will find a list of validators by their category.
206201
- [Undef][] - `v::undef()->assert('');`
207202
- [UndefOr][] - `v::undefOr(v::alpha())->assert('');`
208203
- [Unique][] - `v::unique()->assert([]);`
209-
- [Uploaded][] - ``
210204
- [Uppercase][] - `v::uppercase()->assert('W3C');`
211205
- [Url][] - `v::url()->assert('http://example.com');`
212206
- [Uuid][] - `v::uuid()->assert('eb3115e5-bd16-4939-ab12-2b95745a30f3');`
213207
- [Version][] - `v::version()->assert('1.0.0');`
214-
- [VideoUrl][] - `v::videoUrl()->assert('https://player.vimeo.com/video/71787467');`
215208
- [Vowel][] - `v::vowel()->assert('aei');`
216209
- [When][] - `v::when(v::intVal(), v::positive(), v::notBlank())->assert(1);`
217210
- [Writable][] - `v::writable()->assert('/path/to/file');`
@@ -272,9 +265,7 @@ In this page you will find a list of validators by their category.
272265
[Factor]: validators/Factor.md "Validates if the input is a factor of the defined dividend."
273266
[FalseVal]: validators/FalseVal.md "Validates if a value is considered as `false`."
274267
[Falsy]: validators/Falsy.md "Validates whether the given input is considered empty or falsy, similar to PHP's `empty()` function."
275-
[Fibonacci]: validators/Fibonacci.md "Validates whether the input follows the Fibonacci integer sequence."
276268
[File]: validators/File.md "Validates whether file input is as a regular filename."
277-
[FilterVar]: validators/FilterVar.md "Validates the input with the PHP's filter_var() function."
278269
[Finite]: validators/Finite.md "Validates if the input is a finite number."
279270
[FloatType]: validators/FloatType.md "Validates whether the type of the input is float."
280271
[FloatVal]: validators/FloatVal.md "Validate whether the input value is float."
@@ -329,16 +320,13 @@ In this page you will find a list of validators by their category.
329320
[ObjectType]: validators/ObjectType.md "Validates whether the input is an object."
330321
[Odd]: validators/Odd.md "Validates whether the input is an odd number or not."
331322
[OneOf]: validators/OneOf.md "Will validate if exactly one inner validator passes."
332-
[PerfectSquare]: validators/PerfectSquare.md "Validates whether the input is a perfect square."
333323
[Pesel]: validators/Pesel.md "Validates PESEL (Polish human identification number)."
334324
[Phone]: validators/Phone.md "Validates whether the input is a valid phone number. This validator requires"
335-
[PhpLabel]: validators/PhpLabel.md "Validates if a value is considered a valid PHP Label,"
336325
[Pis]: validators/Pis.md "Validates a Brazilian PIS/NIS number ignoring any non-digit char."
337326
[PolishIdCard]: validators/PolishIdCard.md "Validates whether the input is a Polish identity card (Dowód Osobisty)."
338327
[PortugueseNif]: validators/PortugueseNif.md "Validates Portugal's fiscal identification number (NIF)."
339328
[Positive]: validators/Positive.md "Validates whether the input is a positive number."
340329
[PostalCode]: validators/PostalCode.md "Validates whether the input is a valid postal code or not."
341-
[PrimeNumber]: validators/PrimeNumber.md "Validates a prime number"
342330
[Printable]: validators/Printable.md "Similar to `Graph` but accepts whitespace."
343331
[Property]: validators/Property.md "Validates an object property against a given validator."
344332
[PropertyExists]: validators/PropertyExists.md "Validates if an object property exists."
@@ -368,12 +356,10 @@ In this page you will find a list of validators by their category.
368356
[Undef]: validators/Undef.md "Validates if the given input is undefined. By _undefined_ we consider `null` or an empty string (`''`)."
369357
[UndefOr]: validators/UndefOr.md "Validates the input using a defined validator when the input is not `null` or an empty string (`''`)."
370358
[Unique]: validators/Unique.md "Validates whether the input array contains only unique values."
371-
[Uploaded]: validators/Uploaded.md "Validates if the given data is a file that was uploaded via HTTP POST."
372359
[Uppercase]: validators/Uppercase.md "Validates whether the characters in the input are uppercase."
373360
[Url]: validators/Url.md "Validates whether the input is a URL."
374361
[Uuid]: validators/Uuid.md "Validates whether the input is a valid UUID. It also supports validation of"
375362
[Version]: validators/Version.md "Validates version numbers using Semantic Versioning."
376-
[VideoUrl]: validators/VideoUrl.md "Validates if the input is a video URL value."
377363
[Vowel]: validators/Vowel.md "Validates whether the input contains only vowels."
378364
[When]: validators/When.md "A ternary validator that accepts three parameters."
379365
[Writable]: validators/Writable.md "Validates if the given input is writable file."

docs/validators/Fibonacci.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

docs/validators/FilterVar.md

Lines changed: 0 additions & 64 deletions
This file was deleted.

docs/validators/PerfectSquare.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

docs/validators/PhpLabel.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)