定制 michele-angioni/phalcon-validators 二次开发

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

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

michele-angioni/phalcon-validators

Composer 安装命令:

composer require michele-angioni/phalcon-validators

包简介

New advanced validators for PHP Phalcon Framework.

README 文档

README

License Latest Stable Version Latest Unstable Version Build Status

Introduction

Phalcon Validators adds several new validators to the few default ones present in Phalcon.

PHP 7.1+ and Phalcon 3.1 are required.

Installation

Support can be installed through Composer, just include "michele-angioni/phalcon-validators": "~2.0" to your composer.json and run composer update or composer install.

Usage

The new validators work in the same way the default validators do. Just pass a new instance of the validator to the Phalcon Validation class, with the desired options, and then validate it.

Available validators with practical examples:

IpValidator

The IpValidator validates a valid ip address.

$data['ip'] = $this->request->getPost('ip');

$validation = new Phalcon\Validation();

$validation->add(
    'ip',
    new MicheleAngioni\PhalconValidators\IpValidator (
        [
            'message' => 'The IP is not valid.'       // Optional
        ]
    )
);

$messages = $validation->validate($data);

if (count($messages)) {
    // Some error occurred, handle messages
    
}

// Validation succeeded without errors

NumericValidator

The default NumericValidator only allows for numeric (i.e. 0-9) characters. Minimum and maximum values can be specified.

Optionally, it can support float values, that is allowing a dot (.) character to separate decimals.

Optionally also signed numbers are supported.

$data['number'] = $this->request->getPost('number');

$validation = new Phalcon\Validation();

$validation->add(
    'number',
    new MicheleAngioni\PhalconValidators\NumericValidator (
        [
            'allowFloat' => true,                                           // Optional, default: false
            'allowSign' => true,                                            // Optional, default: false
            'min' => 2,                                                     // Optional
            'min' => 2,                                                     // Optional
            'max' => 50,                                                    // Optional
            'message' => 'Only numeric (0-9,.) characters are allowed.',    // Optional
            'messageMinimum' => 'The value must be at least 2',             // Optional
            'messageMaximum' => 'The value must be lower than 50'           // Optional
        ]
    )
);

$messages = $validation->validate($data);

if (count($messages)) {
    // Some error occurred, handle messages
    
}

// Validation succeeded without errors

AlphaNumericValidator

The AlphaNumericValidator allows for alphanumeric characters. Optionally, it can allow underscores, minuses and white spaces. Minimum and maximum string lengths can be specified.

$data['text'] = $this->request->getPost('text');

$validation = new Phalcon\Validation();

$validation->add(
    'text',
    new MicheleAngioni\PhalconValidators\AlphaNumericValidator (
        [
            'whiteSpace' => true,                                                       // Optional, default false
            'underscore' => true,                                                       // Optional, default false
            'minus' => true,                                                            // Optional, default false
            'min' => 6,                                                                 // Optional
            'max' => 30,                                                                // Optional     
            'message' => 'Validation failed.',                                          // Optional
            'messageMinimum' => 'The value must contain at least 6 characters.',        // Optional
            'messageMaximum' => 'The value can contain maximum 30 characters.'          // Optional
        ]
    )
);

$messages = $validation->validate($data);

if (count($messages)) {
    // Some error occurred, handle messages
    
}

// Validation succeeded without errors

AlphaNamesValidator

The AlphaNamesValidator allows for alphabetic, menus, apostrophe, underscore and white space characters. Optionally, it can allow also numbers (i.t. 0-9). Minimum and maximum string lengths can be specified.

$data['text'] = $this->request->getPost('text');

$validation = new Phalcon\Validation();

$validation->add(
    'text',
    new MicheleAngioni\PhalconValidators\AlphaNamesValidator (
        [
            'numbers' => true,                                                          // Optional, default false
            'min' => 6,                                                                 // Optional
            'max' => 30,                                                                // Optional     
            'message' => 'Validation failed.',                                          // Optional
            'messageMinimum' => 'The value must contain at least 6 characters.',        // Optional
            'messageMaximum' => 'The value can contain maximum 30 characters.'          // Optional
        ]
    )
);

$messages = $validation->validate($data);

if (count($messages)) {
    // Some error occurred, handle messages
    
}

// Validation succeeded without errors

AlphaCompleteValidator

The AlphaCompleteValidator allows for alphanumeric, underscore, white space, slash, apostrophe, round and square brackets/parentheses and punctuation characters. Optionally, it can allow also pipes (|), ATs (@), backslashes (), percentages (%) and Url Characters (equals (=) and hashtags (#)). Minimum and maximum string lengths can be specified.

$data['text'] = $this->request->getPost('text');

$validation = new Phalcon\Validation();

$validation->add(
    'text',
    new MicheleAngioni\PhalconValidators\AlphaCompleteValidator (
        [
            'allowBackslashes' => true,                                                 // Optional
            'allowAt' => true,                                                          // Optional
            'allowPipes' => true,                                                       // Optional
            'allowPercentages' => true,                                                 // Optional
            'allowUrlChars' => true,                                                    // Optional
            'min' => 6,                                                                 // Optional
            'max' => 30,                                                                // Optional     
            'message' => 'Validation failed.',                                          // Optional
            'messageMinimum' => 'The value must contain at least 6 characters.',        // Optional
            'messageMaximum' => 'The value can contain maximum 30 characters.'          // Optional
        ]
    )
);

$messages = $validation->validate($data);

if (count($messages)) {
    // Some error occurred, handle messages
    
}

// Validation succeeded without errors

FileNameValidator

The FileNameValidator allows for a valid file name with extension, allowing simple letters, numbers underscores and minuses. Optionally, it can allow also all Latin characters, multiple dots and white spaces. Minimum and maximum string lengths can be specified.

$data['text'] = $this->request->getPost('text');

$validation = new Phalcon\Validation();

$validation->add(
    'text',
    new MicheleAngioni\PhalconValidators\FileNameValidator (
        [
            'allowMultipleDots' => true,                                                // Optional
            'allowAllLatin' => true,                                                    // Optional
            'allowSpaces' => true,                                                      // Optional
            'min' => 6,                                                                 // Optional
            'max' => 30,                                                                // Optional
            'message' => 'Validation failed.',                                          // Optional
            'messageMinimum' => 'The value must contain at least 6 characters.',        // Optional
            'messageMaximum' => 'The value can contain maximum 30 characters.'          // Optional
        ]
    )
);

$messages = $validation->validate($data);

if (count($messages)) {
    // Some error occurred, handle messages

}

// Validation succeeded without errors

Contribution guidelines

Phalcon Validators follows PSR-1, PSR-2 and PSR-4 PHP coding standards, and semantic versioning.

Pull requests are welcome.

License

Phalcon Validators is free software distributed under the terms of the MIT license.

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固