diff --git a/README.md b/README.md index f6d26121..40d789af 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/docs/concrete-api.md b/docs/concrete-api.md deleted file mode 100644 index 2093fce1..00000000 --- a/docs/concrete-api.md +++ /dev/null @@ -1,91 +0,0 @@ - - -# 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). diff --git a/docs/index.md b/docs/index.md index 7ca550c6..8d9efbb3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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.