mezon / security
小型安全脚本
1.1.6
2023-03-21 16:19 UTC
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
简介
Mezon 提供了一组类,可以帮助您验证前端的数据
安装
只需在控制台打印
composer require mezon/security
就是这样)
文件验证
大小验证
首先,您需要创建文件大小的验证器
use \Mezon\Security; // here we set that file must not be greater then 2KB $sizeValidator = new Validators\File\Size(2 * Validators\File\Size::KB);
然后您可以运行验证
$security = new SecurityRules(); $security->isUploadedFileValid('uploaded-file', $validators);
这里 'uploaded-file' 是 $_FILES 数组中的索引。
MIME 类型验证
您可以验证上传文件的 MIME 类型。为此,构建特殊的验证器,并将有效 MIME 类型的列表传递给其构造函数
// here we set that file must not be greater then 2KB $sizeValidator = new Validators\File\MymeType(['image/png', 'image/jpeg', 'image/jpg']);
然后像上面的例子一样调用 isUploadedFileValid。
图像验证器
您可以使用验证器来验证图像大小
new Mezon\Security\Validators\File\ImageMaximumWidthHeight(<maximum width>, <maximum height>); // and new Mezon\Security\Validators\File\ImageMinimumWidthHeight(<minimum width>, <minimum height>);