mezon / security
Small security script
Installs: 7 779
Dependents: 3
Suggesters: 0
Security: 0
Stars: 3
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: >=7.2.0
- mezon/infrastructure-layer: >=1.2.1 <1.3.0
Requires (Dev)
- infection/infection: ^0.21.5
- phpunit/php-token-stream: 3.1.2
- phpunit/phpunit: ^8.5
- vimeo/psalm: ^4.2
README
Intro
Mezon provides set of classes wich will help you to validate data from front-end
Installation
Just print in console
composer require mezon/security
And that's all )
Files validations
Size validations
First of all you need to create validator for the file size:
use \Mezon\Security; // here we set that file must not be greater then 2KB $sizeValidator = new Validators\File\Size(2 * Validators\File\Size::KB);
Then you can run validation
$security = new SecurityRules(); $security->isUploadedFileValid('uploaded-file', $validators);
Here 'uploaded-file' is an index in the $_FILES array.
Mime-types validations
You can validate mime types of the uploading files. To do this construct special validator and pass a list of valid mime types to it's constructor
// here we set that file must not be greater then 2KB $sizeValidator = new Validators\File\MymeType(['image/png', 'image/jpeg', 'image/jpg']);
And then call isUploadedFileValid like in the example above.
Image validators
You can use validators for the image size:
new Mezon\Security\Validators\File\ImageMaximumWidthHeight(<maximum width>, <maximum height>); // and new Mezon\Security\Validators\File\ImageMinimumWidthHeight(<minimum width>, <minimum height>);