Skip to content

Commit

Permalink
Rename method "validate()" to "isValid()"
Browse files Browse the repository at this point in the history
The method has been renamed some time ago, but I haven't updated the
documentation to cause less confusion. Now that I want to start updating
the documentation, I switched the default branch on GitHub to the latest
stable version, so I assume there will be less confusion in the
documentation, and I can start updating the docs for the next version.
  • Loading branch information
henriquemoody committed Dec 2, 2024
1 parent b894593 commit 061a3c9
Show file tree
Hide file tree
Showing 163 changed files with 558 additions and 558 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

The most awesome validation engine ever created for PHP.

- Complex rules made simple: `v::numericVal()->positive()->between(1, 255)->validate($input)`.
- Complex rules made simple: `v::numericVal()->positive()->between(1, 255)->isValid($input)`.
- [Granularity control](docs/02-feature-guide.md#validation-methods) for advanced reporting.
- [More than 150](docs/08-list-of-rules-by-category.md) (fully tested) validation rules.
- [A concrete API](docs/05-concrete-api.md) for non fluent usage.
Expand Down
22 changes: 11 additions & 11 deletions docs/02-feature-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The Hello World validator is something like this:

```php
$number = 123;
v::numericVal()->validate($number); // true
v::numericVal()->isValid($number); // true
```

## Chained validation
Expand All @@ -25,7 +25,7 @@ containing numbers and letters, no whitespace and length between 1 and 15.

```php
$usernameValidator = v::alnum()->noWhitespace()->length(1, 15);
$usernameValidator->validate('alganet'); // true
$usernameValidator->isValid('alganet'); // true
```

## Validating object properties
Expand All @@ -44,7 +44,7 @@ Is possible to validate its properties in a single chain:
$userValidator = v::property('name', v::stringType()->length(1, 32))
->property('birthdate', v::dateTimeDiff(v::greaterThanOrEqual(18), 'years'));

$userValidator->validate($user); // true
$userValidator->isValid($user); // true
```

Validating array keys is also possible using `v::key()`
Expand Down Expand Up @@ -93,11 +93,11 @@ For that reason all rules are mandatory now but if you want to treat a value as
optional you can use `v::optional()` rule:

```php
v::alpha()->validate(''); // false input required
v::alpha()->validate(null); // false input required
v::alpha()->isValid(''); // false input required
v::alpha()->isValid(null); // false input required

v::optional(v::alpha())->validate(''); // true
v::optional(v::alpha())->validate(null); // true
v::optional(v::alpha())->isValid(''); // true
v::optional(v::alpha())->isValid(null); // true
```

By _optional_ we consider `null` or an empty string (`''`).
Expand All @@ -109,17 +109,17 @@ See more on [Optional](rules/UndefOr.md).
You can use the `v::not()` to negate any rule:

```php
v::not(v::intVal())->validate(10); // false, input must not be integer
v::not(v::intVal())->isValid(10); // false, input must not be integer
```

## Validator reuse

Once created, you can reuse your validator anywhere. Remember `$usernameValidator`?

```php
$usernameValidator->validate('respect'); //true
$usernameValidator->validate('alexandre gaigalas'); // false
$usernameValidator->validate('#$%'); //false
$usernameValidator->isValid('respect'); //true
$usernameValidator->isValid('alexandre gaigalas'); // false
$usernameValidator->isValid('#$%'); //false
```

## Exception types
Expand Down
6 changes: 3 additions & 3 deletions docs/05-concrete-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ or magic methods. We'll use a traditional dependency injection approach.
use Respect\Validation\Validator as v;

$usernameValidator = v::alnum()->noWhitespace()->length(1, 15);
$usernameValidator->validate('alganet'); // true
$usernameValidator->isValid('alganet'); // true
```

If you `var_dump($usernameValidator)`, you'll see a composite of objects with
Expand All @@ -24,7 +24,7 @@ $usernameValidator = new Rules\AllOf(
new Rules\NoWhitespace(),
new Rules\Length(1, 15)
);
$usernameValidator->validate('alganet'); // true
$usernameValidator->isValid('alganet'); // true
```

This is still a very lean API. You can use it in any dependency injection
Expand All @@ -39,7 +39,7 @@ $usernameValidator = new Rules\AllOf(
new Rules\Length(1, 15)
);
$userValidator = new Rules\Key('name', $usernameValidator);
$userValidator->validate(['name' => 'alganet']); // true
$userValidator->isValid(['name' => 'alganet']); // true
```

## How It Works?
Expand Down
10 changes: 5 additions & 5 deletions docs/07-comparable-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ that can be parsed by PHP
Below you can see some examples:

```php
v::greaterThanOrEqual(100)->validate($collection); // true if it has at least 100 items
v::greaterThanOrEqual(100)->isValid($collection); // true if it has at least 100 items

v::dateTime()
->between(new DateTime('yesterday'), new DateTime('tomorrow'))
->validate(new DateTime('now')); // true
->isValid(new DateTime('now')); // true

v::numericVal()->lessThanOrEqual(10)->validate(5); // true
v::numericVal()->lessThanOrEqual(10)->isValid(5); // true

v::stringVal()->between('a', 'f')->validate('d'); // true
v::stringVal()->between('a', 'f')->isValid('d'); // true

v::dateTime()->between('yesterday', 'tomorrow')->validate('now'); // true
v::dateTime()->between('yesterday', 'tomorrow')->isValid('now'); // true
```
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The most awesome validation engine ever created for PHP.

- Complex rules made simple: `v::numericVal()->positive()->between(1, 255)->validate($input)`.
- Complex rules made simple: `v::numericVal()->positive()->between(1, 255)->isValid($input)`.
- [Granularity control](02-feature-guide.md#validation-methods) for advanced reporting.
- [More than 150](08-list-of-rules-by-category.md) (fully tested) validation rules.
- [A concrete API](05-concrete-api.md) for non fluent usage.
2 changes: 1 addition & 1 deletion docs/rules/AllOf.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Will validate if all inner validators validates.

```php
v::allOf(v::intVal(), v::positive())->validate(15); // true
v::allOf(v::intVal(), v::positive())->isValid(15); // true
```

## Categorization
Expand Down
12 changes: 6 additions & 6 deletions docs/rules/Alnum.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Alphanumeric is a combination of alphabetic (a-z and A-Z) and numeric (0-9)
characters.

```php
v::alnum()->validate('foo 123'); // false
v::alnum(' ')->validate('foo 123'); // true
v::alnum()->validate('100%'); // false
v::alnum('%')->validate('100%'); // true
v::alnum('%', ',')->validate('10,5%'); // true
v::alnum()->isValid('foo 123'); // false
v::alnum(' ')->isValid('foo 123'); // true
v::alnum()->isValid('100%'); // false
v::alnum('%')->isValid('100%'); // true
v::alnum('%', ',')->isValid('10,5%'); // true
```

You can restrict case using the [Lowercase](Lowercase.md) and
[Uppercase](Uppercase.md) rules.

```php
v::alnum()->uppercase()->validate('example'); // false
v::alnum()->uppercase()->isValid('example'); // false
```

Message template for this validator includes `{{additionalChars}}` as the string
Expand Down
12 changes: 6 additions & 6 deletions docs/rules/Alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ Validates whether the input contains only alphabetic characters. This is similar
to [Alnum](Alnum.md), but it does not allow numbers.

```php
v::alpha()->validate('some name'); // false
v::alpha(' ')->validate('some name'); // true
v::alpha()->validate('Cedric-Fabian'); // false
v::alpha('-')->validate('Cedric-Fabian'); // true
v::alpha('-', '\'')->validate('\'s-Gravenhage'); // true
v::alpha()->isValid('some name'); // false
v::alpha(' ')->isValid('some name'); // true
v::alpha()->isValid('Cedric-Fabian'); // false
v::alpha('-')->isValid('Cedric-Fabian'); // true
v::alpha('-', '\'')->isValid('\'s-Gravenhage'); // true
```

You can restrict case using the [Lowercase](Lowercase.md) and
[Uppercase](Uppercase.md) rules.

```php
v::alpha()->uppercase()->validate('example'); // false
v::alpha()->uppercase()->isValid('example'); // false
```

## Categorization
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/AlwaysInvalid.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Validates any input as invalid.

```php
v::alwaysInvalid()->validate('whatever'); // false
v::alwaysInvalid()->isValid('whatever'); // false
```

## Categorization
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/AlwaysValid.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Validates any input as valid.

```php
v::alwaysValid()->validate('whatever'); // true
v::alwaysValid()->isValid('whatever'); // true
```

## Categorization
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/AnyOf.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This is a group validator that acts as an OR operator.

```php
v::anyOf(v::intVal(), v::floatVal())->validate(15.5); // true
v::anyOf(v::intVal(), v::floatVal())->isValid(15.5); // true
```

In the sample above, `IntVal()` doesn't validates, but `FloatVal()` validates,
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/ArrayType.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Validates whether the type of an input is array.

```php
v::arrayType()->validate([]); // true
v::arrayType()->validate([1, 2, 3]); // true
v::arrayType()->validate(new ArrayObject()); // false
v::arrayType()->isValid([]); // true
v::arrayType()->isValid([1, 2, 3]); // true
v::arrayType()->isValid(new ArrayObject()); // false
```

## Categorization
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/ArrayVal.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Validates if the input is an array or if the input can be used as an array
(instance of `ArrayAccess` or `SimpleXMLElement`).

```php
v::arrayVal()->validate([]); // true
v::arrayVal()->validate(new ArrayObject); // true
v::arrayVal()->validate(new SimpleXMLElement('<xml></xml>')); // true
v::arrayVal()->isValid([]); // true
v::arrayVal()->isValid(new ArrayObject); // true
v::arrayVal()->isValid(new SimpleXMLElement('<xml></xml>')); // true
```

## Categorization
Expand Down
10 changes: 5 additions & 5 deletions docs/rules/Base.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
Validate numbers in any base, even with non regular bases.

```php
v::base(2)->validate('011010001'); // true
v::base(3)->validate('0120122001'); // true
v::base(8)->validate('01234567520'); // true
v::base(16)->validate('012a34f5675c20d'); // true
v::base(2)->validate('0120122001'); // false
v::base(2)->isValid('011010001'); // true
v::base(3)->isValid('0120122001'); // true
v::base(8)->isValid('01234567520'); // true
v::base(16)->isValid('012a34f5675c20d'); // true
v::base(2)->isValid('0120122001'); // false
```

## Categorization
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/Base64.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Validate if a string is Base64-encoded.

```php
v::base64()->validate('cmVzcGVjdCE='); // true
v::base64()->validate('respect!'); // false
v::base64()->isValid('cmVzcGVjdCE='); // true
v::base64()->isValid('respect!'); // false
```

## Categorization
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/Between.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Validates whether the input is between two other values.

```php
v::intVal()->between(10, 20)->validate(10); // true
v::intVal()->between(10, 20)->validate(15); // true
v::intVal()->between(10, 20)->validate(20); // true
v::intVal()->between(10, 20)->isValid(10); // true
v::intVal()->between(10, 20)->isValid(15); // true
v::intVal()->between(10, 20)->isValid(20); // true
```

Validation makes comparison easier, check out our supported
Expand Down
10 changes: 5 additions & 5 deletions docs/rules/BetweenExclusive.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Validates whether the input is between two other values, exclusively.

```php
v::betweenExclusive(10, 20)->validate(10); // true
v::betweenExclusive('a', 'e')->validate('c'); // true
v::betweenExclusive(new DateTime('yesterday'), new DateTime('tomorrow'))->validate(new DateTime('today')); // true
v::betweenExclusive(10, 20)->isValid(10); // true
v::betweenExclusive('a', 'e')->isValid('c'); // true
v::betweenExclusive(new DateTime('yesterday'), new DateTime('tomorrow'))->isValid(new DateTime('today')); // true

v::betweenExclusive(0, 100)->validate(100); // false
v::betweenExclusive('a', 'z')->validate('a'); // false
v::betweenExclusive(0, 100)->isValid(100); // false
v::betweenExclusive('a', 'z')->isValid('a'); // false
```

Validation makes comparison easier, check out our supported [comparable values](../07-comparable-values.md).
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/BoolType.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Validates whether the type of the input is [boolean](http://php.net/types.boolean).

```php
v::boolType()->validate(true); // true
v::boolType()->validate(false); // true
v::boolType()->isValid(true); // true
v::boolType()->isValid(false); // true
```

## Categorization
Expand Down
12 changes: 6 additions & 6 deletions docs/rules/BoolVal.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Validates if the input results in a boolean value:

```php
v::boolVal()->validate('on'); // true
v::boolVal()->validate('off'); // true
v::boolVal()->validate('yes'); // true
v::boolVal()->validate('no'); // true
v::boolVal()->validate(1); // true
v::boolVal()->validate(0); // true
v::boolVal()->isValid('on'); // true
v::boolVal()->isValid('off'); // true
v::boolVal()->isValid('yes'); // true
v::boolVal()->isValid('no'); // true
v::boolVal()->isValid(1); // true
v::boolVal()->isValid(0); // true
```

## Categorization
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Bsn.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Validates a Dutch citizen service number ([BSN](https://nl.wikipedia.org/wiki/Burgerservicenummer)).

```php
v::bsn()->validate('612890053'); // true
v::bsn()->isValid('612890053'); // true
```

## Categorization
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Call.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ v::call(
->key('host', v::domain())
->key('path', v::stringType())
->key('query', v::notEmpty())
)->validate($url);
)->isValid($url);
```

## Categorization
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/CallableType.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Validates whether the pseudo-type of the input is [callable](http://php.net/types.callable).

```php
v::callableType()->validate(function () {}); // true
v::callableType()->validate('trim'); // true
v::callableType()->validate([new DateTime(), 'format']); // true
v::callableType()->isValid(function () {}); // true
v::callableType()->isValid('trim'); // true
v::callableType()->isValid([new DateTime(), 'format']); // true
```

## Categorization
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ v::callback(
function (int $input): bool {
return $input + ($input / 2) == 15;
}
)->validate(10); // true
)->isValid(10); // true
```

## Categorization
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/Charset.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Validates if a string is in a specific charset.

```php
v::charset('ASCII')->validate('açúcar'); // false
v::charset('ASCII')->validate('sugar'); //true
v::charset('ISO-8859-1', 'EUC-JP')->validate('日本国'); // true
v::charset('ASCII')->isValid('açúcar'); // false
v::charset('ASCII')->isValid('sugar'); //true
v::charset('ISO-8859-1', 'EUC-JP')->isValid('日本国'); // true
```

The array format is a logic OR, not AND.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Cnh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Validates a Brazilian driver's license.

```php
v::cnh()->validate('02650306461'); // true
v::cnh()->isValid('02650306461'); // true
```

## Categorization
Expand Down
Loading

0 comments on commit 061a3c9

Please sign in to comment.