mezon/security

Small security script

1.1.6 2023-03-21 16:19 UTC

This package is auto-updated.

Last update: 2024-04-21 18:41:19 UTC


README

Build Status Scrutinizer Code Quality codecov

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>);

I'll be very glad if you'll press "STAR" button )