定制 horat1us/yii2-validation-exception 二次开发

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

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

horat1us/yii2-validation-exception

Composer 安装命令:

composer require horat1us/yii2-validation-exception

包简介

Yii2 Validation Exception

README 文档

README

Test & Lint codecov

This package add additional methods and exception for model validation.
Main purpose is to prevent mistakes while models validations (forgot to check validation result for failse etc).

Previous implementation was available in horat1us/yii2-base package as ModelExceptionInterface and ModelException.

Installation

Using packagist.org:

composer require horat1us/yii2-validation-exception:^1.0

Structure

Should be used when ActiveRecord is implemented out of project repository (working with dependencies).

Should be used when ActiveRecord implemented in project repository and may implement interfaces and use traits.

  • Validation\Failure\ModelInterface - extends \yii\base\Model with methods validateOrFail and checkOrFail.
    • Model - trait with implementation.
  • [Validation\Failure\ActiveRecordInterface] - extends \yii\db\ActiveRecord with saveOrFail method.

Example

With extension for model and active record:

<?php

namespace App;

use Horat1us\Yii\Validation;
use yii\base;

class Model extends base\Model implements Validation\Failure\ModelInterface
{
    use Validation\Failure\Model;
    
    public $id;
    
    public function rules(): array {
        return [
            [['id',], 'required',],    
        ];
    }
}

$model = new Model;
try {
    $model->validateOrFail();
} catch (Validation\Failure $failure) {
    // handle
}

With exceptions factory:

<?php

namespace App;

use Horat1us\Yii\Validation;
use yii\base;

class Model extends base\Model 
{
    /** @var string  */
    public $id;
    
    public function rules() {
        return [
            [['id',], 'required',],
        ];
    }
}

$model = new Model;

try {
    Validation\Exception::validateOrThrow($model);
} catch (Validation\Failure $failure) {
    // handle
}

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固