PHPackages                             othercodes/ddd-value-object - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. othercodes/ddd-value-object

Abandoned → [complex-heart/domain-model](/?search=complex-heart%2Fdomain-model)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

othercodes/ddd-value-object
===========================

Small library to easily apply the Value Object Pattern.

v1.1.0(5y ago)1174MITPHP

Since Oct 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/othercodes/ddd-value-object)[ Packagist](https://packagist.org/packages/othercodes/ddd-value-object)[ RSS](/packages/othercodes-ddd-value-object/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (6)Versions (5)Used By (0)

DDD Value Object
================

[](#ddd-value-object)

[![Tests](https://github.com/othercodes/ddd-value-object/workflows/Tests/badge.svg)](https://github.com/othercodes/ddd-value-object/workflows/Tests/badge.svg) [![License](https://camo.githubusercontent.com/51ac1a0cdae02062fdaea447b55b44af7f8df7b36055bc1002a7ade35ef60e16/68747470733a2f2f706f7365722e707567782e6f72672f6f74686572636f6465732f6464642d76616c75652d6f626a6563742f6c6963656e7365)](https://packagist.org/packages/othercodes/ddd-value-object) [![codecov](https://camo.githubusercontent.com/b052574891e2b57dd03e0b98647cdad4881bf3ae37dcf1447ff215004e23e93b/68747470733a2f2f636f6465636f762e696f2f67682f6f74686572636f6465732f6464642d76616c75652d6f626a6563742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/othercodes/ddd-value-object)

Small library to easily manage the Value Object Pattern.

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

[](#installation)

Use the following command to install with `composer`:

```
composer require othercode/ddd-value-object
```

This will automatically get the latest version and configure a `composer.json` file.

Alternatively you can create the following `composer.json` file and run `composer install` to install it.

```
{
    "require": {
        "othercode/ddd-value-object": "*"
    }
}
```

Usage
-----

[](#usage)

Build a Value object is quite simple, you just need to extend the `ValueObject` Next, initialize the values in the constructor by using the `initialize` method. Finally, add invariant rules as protected method, using the prefix `invariant` (this prefix can be customized) and execute them with the `checkInvariants` method.

```
