ipedis / validation-handler
There is no license information available for the latest version (2.1.0) of this package.
File validation handler
2.1.0
2026-02-04 14:09 UTC
Requires
- php: >=8.2
- symfony/mime: 7.4.*
- symfony/validator: 7.4.*
Requires (Dev)
- laravel/pint: ^1.20
- pestphp/pest: ^3.8
- phpstan/phpstan: ^2.1
- rector/rector: ^2.3
- symfony/var-dumper: 7.4.*
This package is auto-updated.
Last update: 2026-04-26 13:07:22 UTC
README
Validation-handler
This library is useful for file validation built on top of symfony/validator component.
Get Started
First you have to install dependency of this library.
make install
make test
How to use?
Prepare your data inside DataWrapper and create validation chain with validators.
use Ipedis\ValidationHandler\Data\DataWrapper; use Ipedis\ValidationHandler\Data\Constraints\FileSize; use Ipedis\ValidationHandler\Data\Constraints\MimeTypes; use Ipedis\ValidationHandler\Validator\Result\ValidationResult; use Ipedis\ValidationHandler\ConstraintFactory; $file = __DIR__."/../tests/data/265kb.pdf"; $data = new DataWrapper(new SplFileInfo($file)); /** * build validator with list of constraints. */ $validator = ConstraintFactory::build(constraints: [ new FileSize('100', 'k'), new MimeTypes(['application/pdf']) ]); // run validations $result = $validation->handle(); var_dump($result->isFailed(), $result->getErrorMessage()); /* * don't want to search for mimetype string? you can use built-in mimetypes helper */ // example of mimetypes helper $validator = ConstraintFactory::build(constraints: [ new FileSize('1', 'M'), MimeTypes::with(PdfMimeType::class) ]); /** @var ValidationResult $result */ $result = $validator->handle($data); // should pass. var_dump($result->isFailed(), $result->getErrorMessage()); /** * If you do not concern about filesize but only want to check if file is image or pdf */ var_dump(ValidationHelper::isImage($data)); var_dump(ValidationHelper::isPdf($data));
Result will be instanced of ValidationResult, isFailed() is helper to know
if validation failed or not. getError() will give you instance of symfony's ConstraintViolationInterface.
Adding more validator
Each validator class extends HandlerAbstract. You can create new class and perform your own required validations.
Limitations and TODO
- For now validation is only for uploaded files, we can expand it to use other types.