decodelabs/lucid
最新稳定版本:v0.8.1
Composer 安装命令:
composer require decodelabs/lucid
包简介
Flexible and expansive sanitisation and validation framework
README 文档
README
Flexible and expansive sanitisation and validation framework for PHP
Lucid provides a unified single-value sanitisation and validation structure for making sure your input makes sense.
Installation
This package requires PHP 8.4 or higher.
Install via Composer:
composer require decodelabs/lucid
Usage
Direct value sanitisation can be achieved quickly and painlessly:
use DecodeLabs\Lucid; $lucid = new Lucid(); // This ensures the value is a string $myString = $lucid->cast('This is a string', 'string'); // This is nullable $notAString = $lucid->cast(null, '?string'); // These are constraints - throws an exception $myString = $lucid->cast('My very long piece of text', 'string', [ 'maxLength' => 10, 'maxWords' => 4 ]); // Creates an instance of Carbon (DateTime) $myDate = $lucid->cast('tomorrow', 'date', [ 'min' => 'yesterday', 'max' => '+3 days' ]);
If you need more fine grained control of the responses to constraints, use validate():
$result = $lucid->validate('potato', 'int', [ 'min' => 4 ]); if(!$result->valid) { // Do something with the potato foreach($result->errors as $error) { echo $error->message; } }
Or conversely if you just need a yes or no answer, use is():
if(!$lucid->is('not a number', 'float')) { // do something }
Custom processors
Lucid uses Archetype to load both Processors and Constraints - implement your own custom classes within DecodeLabs\Lucid\Processor or DecodeLabs\Lucid\Constraint namespaces, or create your own Archetype Resolver to load them from elsewhere.
Please see the selection of existing implementations for details on how to build your own custom classes.
Provider interfaces
Lucid builds on a sub-package, Lucid Support which makes available a set of Provider interfaces to enable embedded implementations of the Sanitizer structure.
Please see the readme in Lucid Support for integrating Lucid into your own libraries.
Licensing
Lucid is licensed under the MIT License. See LICENSE for the full license text.
统计信息
- 总下载量: 19.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 3
- 依赖项目数: 12
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-07