ixudra/validation
Composer 安装命令:
composer require ixudra/validation
包简介
Custom Laravel validation library - developer by Ixudra
关键字:
README 文档
README
Custom PHP validation library - developed by Ixudra.
This package provides a wide variety of validation rules for PHP web applications. These rules can be used to easily validate user input to make sure that it meets the requirements that you have set.
Please also note that this package is intended for, but not exclusive to the Laravel framework. This basically means that
most validation methods are universally usable in any PHP application but some make use of internal Laravel components
(e.g. see UserValidationTrait). These methods will probably not work correctly unless you also include the used dependencies
in you application as well.
This package can be used by anyone at any given time, but keep in mind that it is optimized for my personal custom workflow. It may not suit your project perfectly and modifications may be in order.
Installation
Pull this package in through Composer.
{ "require": { "ixudra/validation": "1.*" } }
Laravel usage
To use this package with Laravel 4 or 5, you will have to extend the default validator class. Once this class is created, you can include the traits into the class to make use of the validation methods. Laravel will automatically pick up the validation rules and make them available to you. Note that you don't have to include all traits if you don't want to. All validation rules are completely independent, which allows for maximum customization.
use Ixudra\Validation\DateValidationTrait; use Ixudra\Validation\TimeValidationTrait; use Ixudra\Validation\ArrayValidationTrait; use Ixudra\Validation\PasswordValidationTrait; use Ixudra\Validation\CoordinateValidationTrait; class CustomValidator extends \Illuminate\Validation\Validator { use DateValidationTrait; use TimeValidationTrait; use ArrayValidationTrait; use PasswordValidationTrait; use CoordinateValidationTrait; }
Next, you will need to add the following to your routes.php to let Laravel know that you want to use your custom validator
class instead of the default one:
Validator::resolver(function($translator, $data, $rules, $messages) { return new CustomValidator($translator, $data, $rules, $messages); });
Once this is done, you are all set to go. You can now include the custom validation rules in the same way you use the default rules that Laravel already provides to you:
$attributes = array( 'att1' => 'john.doe@gmail.com', 'att2' => 0, 'att3' => date('Y-m-d', strtotime('next week')) ); $rules = array( 'att1' => 'required|email', 'att2' => 'required|truthy', 'att3' => 'required|future' ); $validator = Validator::make( $attributes, $rules ); $validator->fails();
Available validation methods
Array Validation
- array_size: validates the size of an array
- one_or_more_selected: returns
trueif an array contains an entry where the value istrue
Date Validation
- past: returns
trueif the value contains a date which is set in the past - future: returns
trueif the value contains a date which is set in the future (not including today) - less_than_three_days_old: returns
trueif the value contains a date which is set less that three days in the past - today_or_later: returns
trueif the value contains a date which is set in the future (including today)
File Validation
- unique_file_name: returns
trueif the value a unique file name. This function expects the full path name of the file starting from the Laravelpublic/directory
JSON Validation
- json: returns
trueis the value contains a valid JSON string
Number Validation
- positive: returns
trueis the value larger than 0 - negative: returns
trueif the value is smaller than 0
Password Validation
- valid_password: returns
trueis the value contains a valid password (at least 6 characters long, at least one lowercase letter, at least one uppercase letter and at least one number) - correct_password: returns
trueif the value contains the correct password for the authenticated user (does not try to re-authenticate the user)
String Validation
- empty: returns
trueif the value contains an empty string
Telephone Validation
- telephone_number: returns
trueif the value contains a valid (Belgian) telephone number
Time Validation
- time: returns
trueif the value contains a valid timestamp - time_format: returns
trueif the value contains a timestamp with the specified format
Truthy Validation
- truthy: returns
trueif the value is eithertrueoffalse - true: returns
trueif the value istrue
User Validation
- email_belongs_to_authenticated_user: returns
trueif the value contains an email address which belongs to the authenticated user - id_belongs_to_authenticated_user: returns
trueif the value contains an ID which belongs to the authenticated user
Have fun!
ixudra/validation 适用场景与选型建议
ixudra/validation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.72k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2014 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「validation」 「laravel」 「Ixudra」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ixudra/validation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ixudra/validation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ixudra/validation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Custom PHP translation library for the Laravel framework - developed by Ixudra
Adds request-parameter validation to the SLIM 3.x PHP framework
Custom PHP geo-location services library for the Laravel 5 framework - developed by Ixudra
A jQuery augmented PHP library for creating and validating HTML forms
Custom PHP resource generation library for the Laravel framework - developed by Ixudra
A Laravel validator for delimiter-separated list of emails.
统计信息
- 总下载量: 2.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-04-12