定制 pravaler/validator 二次开发

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

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

pravaler/validator

Composer 安装命令:

composer require pravaler/validator

包简介

Validation using the symfony components, but in the laravel style

README 文档

README

Create a component using Synfony validations in the style of Laravel

Supported Symfony Versions

4.x Symfony

Installation

Download the package

$ composer require pravaler/validator

Using

Example:

<?php

namespace App\Controller;

use Pravaler\Component\Validator\Validator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class PostController extends Controller
{
    public function savePost(Request $request)
    {
        $data = $request->request->all();
        
        $validator = new Validator([
            'name' => 'required',
            'author' => 'required',
            'email' => 'required|email',
            'description' => 'required|size:1:500'
        ]);
        $validator->validate($data);
        if (!$validator->isValid()) {
            return $this->render("post/index.html.twig", [
                'errors' => $validator->getViolations()
            ]);
        }
        
        return $this->render("post/index.html.twig", [
            'message' => 'The post is valid!'
        ]);
    }
}

Possible Validations

Cpf

$validator = new Validator([
    'field' => 'cpf',
]);

Email

$validator = new Validator([
    'field' => 'email',
]);

Max

$validator = new Validator([
    'field' => 'max:10',
]);

Min

$validator = new Validator([
    'field' => 'min:5',
]);

Numeric

$validator = new Validator([
    'field' => 'numeric',
]);

Password Confirm

// In order for the password confirm to take effect it is necessary to have in the data the password field

$validator = new Validator([
    'field' => 'password_confirm',
]);

Required

$validator = new Validator([
    'field' => 'required',
]);

Size

$validator = new Validator([
    'field' => 'size:1:500',
]);

regex

$validator = new Validator([
    'field' => 'regex:/[1-9]{2}\9\d{8}/',
]);

License

This project is licensed under the MIT license. For more information, see the license file included in this bundle.

Based

Created based on symfony/validator

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固