PHPackages                             jeffersoncechinel/attribute-validator - 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. jeffersoncechinel/attribute-validator

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

jeffersoncechinel/attribute-validator
=====================================

v1.0.3(1y ago)523MITPHPPHP &gt;=8.0

Since Aug 15Pushed 1y ago2 watchersCompare

[ Source](https://github.com/jeffersoncechinel/attribute-validator)[ Packagist](https://packagist.org/packages/jeffersoncechinel/attribute-validator)[ RSS](/packages/jeffersoncechinel-attribute-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Attribute Validator
===================

[](#attribute-validator)

### Elegantly validates PHP class properties

[](#elegantly-validates-php-class-properties)

Attribute Validator allows you to set declarative validation rules on top of PHP class properties. It heavily relies on PHP &gt;=8.x Reflection Api to extract the Attributes for validation.

It suits well for domain models(DDD) and DTO validations which tends to get fat and complicated over the time. To counterpart this scenario this library helps decoupling models and dtos from the validation process avoiding tons of manual validations in setter methods.

[![License: MIT](https://camo.githubusercontent.com/1a2e0606685ce00663bf829868f794fd3fc9c86f8d80cae324734129e0723a58/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d627269676874677265656e2e737667)](https://opensource.org/licenses/MIT)

Supported error types
---------------------

[](#supported-error-types)

- Aggregatable - Aggregates multiple error messages in one validation run.
- Throwable - Throws an exception as soon as a fail validation occurs.

List of rules
-------------

[](#list-of-rules)

- NotNull - Validate if value is not null.
- Length - Validates the range of a string value.
- Number - Validates if a value is numeric.
- Email - Validates if and email is valid.
- Range - Validates if value number is in range.
- Datetime - Validates datetime, date and time in any format.
- UUID - Validates if value is in uuid format.
- ...

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0

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

[](#installation)

Use [composer](https://getcomposer.org/download/) package manager.

```
composer require jeffersoncechinel/attribute-validator
```

Usage example
-------------

[](#usage-example)

A simple example on validating a class properties.

```
