定制 bdbch/vivalidator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

bdbch/vivalidator

Composer 安装命令:

composer require bdbch/vivalidator

包简介

Data validation library for simple input validations

README 文档

README

Screenshot of a form validated with Vivalidator

Vivalidator

A simple and easy input and data validation library

Why?

I dislike the way of using Wordpress Plugins or heavy PHP packages for form development when it comes to Wordpress forms. I hate when third party code adds markup to your page or narrows my possibilites because of some restrictions coming with the external code. Thats why I started looking for easy to use validation frameworks but didn't find anything that perfectly fits my needs. This is why I started development on Vivalidator.

Installation

The Composer Way

Run composer require bdbch/vivalidator in your project folder to install Vivalidator via Composer. It will be automatically placed into your autoload.

Manual Way

Make sure to have all necessary files copied manually into your project. Require the desired library from the src folder in your code to get access to a Vivalidator Class.

Usage

Using the Validator is simple. Check out this example code to get an idea on how to use this feature.

<?php

// Make sure to use the feature in your component
use Vivalidator\Validator;

// Data to validate. I left the job empty on purpose to demonstrate non-valid data
$data = [
  'name' => 'Peter',
  'age' => '23',
  'job' => ''
];

// Validator Options / Rules
// Each field can have multiple rules with their own error messages
$options = [
  'name' => [
    [
      'rule' => 'required',
      'error' => 'Please enter your name'
    ],
    [
      'rule' => 'minlength',
      'value' => 3,
      'error' => 'Your name needs to be longer than 3 characters.'
    ]
  ],
  'age' => [
    [
      'rule' => 'required',
      'error' => 'Please enter your age'
    ],
    [
      'rule' => 'min',
      'value' => 1,
      'error' => 'You need to be older than 1'
    ],
    [
      'rule' => 'max',
      'value' => 150,
      'error' => 'I would love to believe you, but I will not'
    ]
  ],
  'job' => [
    [
      'rule' => 'required',
      'error' => 'Please specify your job'
    ]
  ]
];

// Create a new validator instance and pass data and options in
$validator = new Validator($data, $options);

// Errors will be collected in an array.
// If there are no errors, it will be an empty string
if (count($validator->errors)) {
  echo 'You have ' . count($validator->errors) . ' errors in your submission.';
  foreach ($validator->errors as $error) {
    echo 'Error: ' . $error;
  }
} else {
  echo 'All set, lets submit!';
}

// Thats it
// You can now do what ever you want with the submitted data
// Make sure to escape the data. The validator doesn't do this right now
// TODO: This will be a feature so fields can be escaped if needed

Adding ReCaptcha

Vivalidator now has ReCaptcha Support! Just specify your Secret Key and the Error String as extra data to configure it right away! Make sure to have the ReCaptcha library installed manually or via composer require google/recaptcha.

// Check this URL if you need a Key
// https://www.google.com/recaptcha/admin
// Make sure you have a working ReCaptcha library installed,
// otherwise this will do nothing
$validator = new Validator($data, $options, [
  'recaptcha' => [
    'secret' => 'YOUR_SECRET_KEY_HERE',
    'error' => 'Please verify our captcha'
  ]
]);

Rules

  • required - Checks if the input is not empty
  • minlength - Checks if the input is longer than a specific value
  • maxlength - Checks if the input is lower than a specific value
  • email - Checks if the input is a valid email
  • url - Checks if the input is an URL
  • number - Checks if the input is a number
  • min - Checks if the input is higher than the defined value
  • max - Checks if the input is lower than the defined value
  • between - Checks if the input is between two numbers (combination of max and min)
  • regex - Checks if the input matches a specified regex

Planned Rules

See this issue to learn more

Contribution

I'm open for pull requests and would love to see some support. I'm not the 100% best PHP developer and would love to get this Flynt feature even better so we're not bound to damn Wordpress Plugins anymore.

License

This is licensed under the MIT license.

bdbch/vivalidator 适用场景与选型建议

bdbch/vivalidator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 08 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bdbch/vivalidator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bdbch/vivalidator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 60
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-29