https://github.com/br0ken-/reflection-validator
Define a specification of PHP entity and check whether the particular item matches it.
https://github.com/br0ken-/reflection-validator
php php7 reflection reflection-library validation validator
Last synced: 9 months ago
JSON representation
Define a specification of PHP entity and check whether the particular item matches it.
- Host: GitHub
- URL: https://github.com/br0ken-/reflection-validator
- Owner: BR0kEN-
- License: mit
- Created: 2017-08-01T15:19:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-07-23T10:51:40.000Z (over 4 years ago)
- Last Synced: 2025-03-26T03:41:33.559Z (10 months ago)
- Topics: php, php7, reflection, reflection-library, validation, validator
- Language: PHP
- Size: 22.5 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reflection Validator
[](https://travis-ci.org/BR0kEN-/reflection-validator)
[](https://scrutinizer-ci.com/g/BR0kEN-/reflection-validator/?branch=master)
[](https://scrutinizer-ci.com/g/BR0kEN-/reflection-validator)
[](https://packagist.org/packages/reflection/validator)
[](https://packagist.org/packages/reflection/validator)
[](https://packagist.org/packages/reflection/validator)
## When might it be useful?
Sometimes you may want to have an unlimited sequence of methods, which cannot be restricted/controlled by the interface. In this case on a "compilation" stage, you can restrict those methods to follow the standards you expect.
A real example from Drupal/Symfony world: http://cgit.drupalcode.org/form_alter_service/tree/src/FormAlterCompilerPass.php
## Examples
Besides of [fully-operable examples](examples), you can check a quick use case:
```php
(new MethodValidator(object, string))
->addArgument(
(new ArgumentSpecification('form'))
->setType('array')
->setOptional(false)
->setPassedByReference(true)
)
->addArgument(
(new ArgumentSpecification('formState'))
->setType(Iterator::class)
->setOptional(false)
->setPassedByReference(false)
);
```