PHPackages                             webcore/validation-traits - 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. webcore/validation-traits

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

webcore/validation-traits
=========================

Simple validation library

v2.0.0(10y ago)2181[1 issues](https://github.com/webcore/validation-traits/issues)1MITPHPPHP &gt;=5.6

Since Jun 8Pushed 10y ago2 watchersCompare

[ Source](https://github.com/webcore/validation-traits)[ Packagist](https://packagist.org/packages/webcore/validation-traits)[ RSS](/packages/webcore-validation-traits/feed)WikiDiscussions master Synced 4w ago

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

[![Travis](https://camo.githubusercontent.com/0c0a1b2e4f6c1ca26ff8e8d9f0dc85927e3b022a0b8a298553e51a647477cf97/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776562636f72652f76616c69646174696f6e2d7472616974732e7376673f6d61784167653d32353932303030)](https://travis-ci.org/webcore/validation-traits)[![SensioLabs Insight](https://camo.githubusercontent.com/20ff721f25b2ff422c6e28cdf446351cc0db9d11597a819784a087503a4a84a8/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f36613136366661622d646466302d346435632d623630352d3039663636383166383739352e7376673f6d61784167653d32353932303030)](https://insight.sensiolabs.com/projects/6a166fab-ddf0-4d5c-b605-09f6681f8795)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/edff2336469f31d7a1367d238abefe89ca3b588809dd2740db39dd0079c7adb0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776562636f72652f76616c69646174696f6e2d7472616974732e7376673f6d61784167653d32353932303030)](https://scrutinizer-ci.com/g/webcore/validation-traits/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/92faaa2c21b123e1aef4f01f7b16d66b1ee10826dca8145e2910108d99e29b3f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776562636f72652f76616c69646174696f6e2d7472616974732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/webcore/validation-traits/?branch=master)[![Dependency Status](https://camo.githubusercontent.com/73b0a834688c5327da9ab0dc2b4ff13f427b279b69fbeff2def05a0e54cba32d/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537353832376163373735376130303034613164653437392f62616467652e7376673f7374796c653d706c6173746963)](https://www.versioneye.com/user/projects/575827ac7757a0004a1de479)[![license](https://camo.githubusercontent.com/98b3df0960d4468ef40bd668f4b7b65faf224e7615c1ad8a3379f423f6f7d67a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f776562636f72652f76616c69646174696f6e2d7472616974732e7376673f6d61784167653d32353932303030)](https://opensource.org/licenses/MIT)

Validation traits
=================

[](#validation-traits)

A PHP library/collection of traits aimed to simplify cration of immutable value objects with validation of input value. Basic idea was also inspired by [Laravel's Validation trait for Eloquent models](https://github.com/dwightwatson/validating) and redesign more towards [nicolopignatelli/valueobjects](https://github.com/nicolopignatelli/valueobjects)

[Version 1.0](https://github.com/webcore/validation-traits/tree/v1.0) has less complex attitude on value objects and provide mainly validation via one trait.

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

[](#installation)

Via Composer

```
composer require webcore/validation-traits

```

### Example

[](#example)

`SingleValueObjectInterface` define getter method to retrieve value and method for comparing with another value objects implementing this interface.

```
interface SingleValueObjectInterface
{
    /**
     * @return mixed
     */
    public function getValue();

    /**
     * Compare two SingleValueObject and tells whether they can be considered equal
     *
     * @param  SingleValueObjectInterface $object
     * @return bool
     */
    public function sameValueAs(SingleValueObjectInterface $object);
}
```

Let's define simple `Token` class with 3 rules:

```
//example/Token.php
