承接 ixudra/validation 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ixudra/validation

Composer 安装命令:

composer require ixudra/validation

包简介

Custom Laravel validation library - developer by Ixudra

README 文档

README

Latest Version on Packagist license StyleCI Total Downloads

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 true if an array contains an entry where the value is true

Date Validation

  • past: returns true if the value contains a date which is set in the past
  • future: returns true if the value contains a date which is set in the future (not including today)
  • less_than_three_days_old: returns true if the value contains a date which is set less that three days in the past
  • today_or_later: returns true if the value contains a date which is set in the future (including today)

File Validation

  • unique_file_name: returns true if the value a unique file name. This function expects the full path name of the file starting from the Laravel public/ directory

JSON Validation

  • json: returns true is the value contains a valid JSON string

Number Validation

  • positive: returns true is the value larger than 0
  • negative: returns true if the value is smaller than 0

Password Validation

  • valid_password: returns true is 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 true if the value contains the correct password for the authenticated user (does not try to re-authenticate the user)

String Validation

  • empty: returns true if the value contains an empty string

Telephone Validation

  • telephone_number: returns true if the value contains a valid (Belgian) telephone number

Time Validation

  • time: returns true if the value contains a valid timestamp
  • time_format: returns true if the value contains a timestamp with the specified format

Truthy Validation

  • truthy: returns true if the value is either true of false
  • true: returns true if the value is true

User Validation

  • email_belongs_to_authenticated_user: returns true if the value contains an email address which belongs to the authenticated user
  • id_belongs_to_authenticated_user: returns true if 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 ixudra/validation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.72k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-12