Update README.md and README.md-linked headline docs

The phrase "granularity control for advanced reporting" is not
accurate anymore. Although we offer much better exception handling
now, we are currently not offering granularity control at a global
level (previously implemented by the check() interface).

If that were to be changed, we can restore that headline. I instead
replaced with the phrase "Advanced exception handling", which
accurately describes what we offer.

I also removed the `concrete-api.md`, which was a document
describing how we don't rely on static calls. We do, in fact,
recommend some of them, such as `ValidatorBuilder::init`, and
although they can be avoided, it relies on setting up a custom
container which we do not offer full documentation for yet.
This commit is contained in:
Alexandre Gomes Gaigalas 2026-02-01 10:54:46 -03:00
commit 0b81dcb4f7
3 changed files with 2 additions and 95 deletions

View file

@ -13,9 +13,8 @@ SPDX-License-Identifier: MIT
The most awesome validation engine ever created for PHP.
- Complex validation made simple: `v::numericVal()->positive()->between(1, 255)->isValid($input)`.
- [Granularity control](docs/handling-exceptions.md) for advanced reporting.
- Advanced [exception handling](docs/handling-exceptions.md).
- [More than 150](docs/validators.md) (fully tested) validators.
- [A concrete API](docs/concrete-api.md) for non fluent usage.
Learn More:

View file

@ -1,91 +0,0 @@
<!--
SPDX-FileCopyrightText: (c) Respect Project Contributors
SPDX-License-Identifier: MIT
-->
# Concrete API
There are many micro-frameworks that rely on magic methods. We don't. In this
document we're going to explore the Respect\Validation API without fluent interfaces
or magic methods. We'll use a traditional dependency injection approach.
```php
use Respect\Validation\ValidatorBuilder as v;
$usernameValidator = v::alnum()->notSpaced()->length(1, 15);
$usernameValidator->isValid('alganet'); // true
```
If you `var_dump($usernameValidator)`, you'll see a composite of objects with
`Respect\Validation\Validators\Alnum`, `Respect\Validation\Validators\Spaced` wrapped in `Respect\Validation\Validators\Not` and
`Respect\Validation\Validators\Length`. There is a specific object for each validator, and
the chain only builds the structure. You can build it by yourself:
```php
use Respect\Validation\Validators;
use Respect\Validation\ValidatorBuilder;
$usernameValidator = ValidatorBuilder::init(
new Validators\Alnum(),
new Validators\Not(
new Validators\Spaced(),
),
new Validators\Length(1, 15),
);
$usernameValidator->isValid('alganet'); // true
```
This is still a very lean API. You can use it in any dependency injection
container or test it in the way you want. Nesting is still possible:
```php
use Respect\Validation\Validators;
$usernameValidator = ValidatorBuilder::init(
new Validators\Key(
'name',
new Validators\AllOf(
new Validators\Alnum(),
new Validators\Not(
new Validators\Spaced(),
),
new Validators\Length(1, 15),
)
)
);
$userValidator->isValid(['name' => 'alganet']); // true
```
## How It Works?
The Respect\Validation chain is an
[internal DSL](http://martinfowler.com/bliki/InternalDslStyle.html).
It acts in the creational realm of objects (where Abstract Factories and Builders
live), and it's only job is to make validator construction terse and fluent.
## FAQ
> Is `v` in `v::something` a class name?
No! The class is `Respect\Validation\ValidatorBuilder`, we suggest `v` as a very short alias.
> Is `v::something()` a static call?
Yes. Just like the default `DateTime::createFromFormat()` or
`Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration()`. It builds
something complex and returns for you.
> I really don't like static calls, can I avoid it?
Yes. Just use `$validator = ValidatorBuilder::create();` each time you want a new validator,
and continue from there.
> Do you have a static method for each validator?
No. We use `__callStatic()`.
> Magic methods are slow! Why do you use them?
They're optional. If you use the `new` interface, they won't be called.
(still, do some benchmarks, you'd be surprised with our implementation).

View file

@ -8,6 +8,5 @@ SPDX-License-Identifier: MIT
The most awesome validation engine ever created for PHP.
- Complex validation made simple: `v::numericVal()->positive()->between(1, 255)->isValid($input)`.
- [Granularity control](handling-exceptions.md) for advanced reporting.
- Advanced [exception handling](handling-exceptions.md).
- [More than 150](validators.md) (fully tested) validators.
- [A concrete API](concrete-api.md) for non fluent usage.