PHPackages                             horat1us/yii2-validation-exception - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. horat1us/yii2-validation-exception

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

horat1us/yii2-validation-exception
==================================

Yii2 Validation Exception

1.1.0(3y ago)02.1k3MITPHPPHP &gt;=7.4

Since Mar 19Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Horat1us/yii2-validation-exception)[ Packagist](https://packagist.org/packages/horat1us/yii2-validation-exception)[ RSS](/packages/horat1us-yii2-validation-exception/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (4)Versions (4)Used By (3)

Yii2 UUID Behavior
==================

[](#yii2-uuid-behavior)

[![Test & Lint](https://github.com/Horat1us/yii2-validation-exception/actions/workflows/php.yml/badge.svg?branch=master)](https://github.com/Horat1us/yii2-validation-exception/actions/workflows/php.yml)[![codecov](https://camo.githubusercontent.com/83743fe80b06b49c3419f620d18c1fbd4750a477fa331cc6f782d07be0ff83c9/68747470733a2f2f636f6465636f762e696f2f67682f486f7261743175732f796969322d76616c69646174696f6e2d657863657074696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Horat1us/yii2-validation-exception)

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](https://github.com/Horat1us/yii2-base) package as ModelExceptionInterface and ModelException.

Installation
------------

[](#installation)

Using [packagist.org](https://packagist.org/packages/horat1us/yii2-validation-exception):

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

Structure
---------

[](#structure)

- [Validation\\Failure](./src/Failure.php) - common interface for validation errors.

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

- [Validation\\ExceptionTrait](./src/ExceptionTrait.php) - implements *Failure* and provides static failure factory.
- [Validation\\Exception](./src/Exception.php) - *Failure* implementation using *ExceptionTrait*.

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

- [Validation\\Failure\\ModelInterface](./src/Failure/ModelInterface.php) - extends `\yii\base\Model` with methods *validateOrFail* and *checkOrFail*.
    - [Model](./src/Failure/Model.php) - trait with implementation.
- \[Validation\\Failure\\ActiveRecordInterface\] - extends `\yii\db\ActiveRecord` with *saveOrFail* method.
    - [ActiveRecord](./src/Failure/ActiveRecord.php) - trait with implementation.

Example
-------

[](#example)

With extension for model and active record:

```
