PHPackages                             noahlvb/valueobject - 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. noahlvb/valueobject

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

noahlvb/valueobject
===================

A php library to bootstrap the use of Domain Driven Design valueObjects

v1.0.2(4y ago)12.2k↓100%11MITPHPPHP ^7.1 || ^8.0

Since Mar 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/noahlvb/php-valueobject)[ Packagist](https://packagist.org/packages/noahlvb/valueobject)[ RSS](/packages/noahlvb-valueobject/feed)WikiDiscussions master Synced 1mo ago

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

PHP Value Object
================

[](#php-value-object)

A library to bootstrap the use of Domain Driven Design valueObjects

[![CI](https://github.com/noahlvb/php-valueobject/workflows/CI/badge.svg?branch=master)](https://github.com/noahlvb/php-valueobject/workflows/CI/badge.svg?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/e277b5eb8418296652919ce1d1d5d0f5436e0fe5b9d965cfc23a2c1709111f95/68747470733a2f2f706f7365722e707567782e6f72672f6e6f61686c76622f76616c75656f626a6563742f762f737461626c65)](https://packagist.org/packages/noahlvb/valueobject)[![License](https://camo.githubusercontent.com/d4f883d4ecd8a3b613a4b8908ba00bd7e61e8fb688bc27f9288c9ee828e43346/68747470733a2f2f706f7365722e707567782e6f72672f6e6f61686c76622f76616c75656f626a6563742f6c6963656e7365)](https://packagist.org/packages/noahlvb/valueobject)

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

[](#installation)

With [composer](http://packagist.org), add:

```
$ composer require noahlvb/valueobject
```

Or if your using Symfony: [valueobject-bundle](https://github.com/noahlvb/php-valueobject-bundle)

```
$ composer require noahlvb/valueobject-bundle
```

Run Tests
---------

[](#run-tests)

To make sure everything works you can run tests:

```
$ make test
```

How to use
----------

[](#how-to-use)

Currently there are two primitive types supported:

- String : ValueObjectString
- Integer : ValueObjectInteger

Creating a simple value object without checks.

```
class Name extends ValueObjectString
{
    protected function sanitize(string $value): string
    {
        return trim($value);
    }

    public function isValid(string $value): bool
    {
        return true;
    }
}
```

If you want to validate a value during construction of a value object, simply override the isValid method with your check:

```
class Name extends ValueObject
{
    protected function sanitize(string $value): string
    {
        return trim($value);
    }

    public function isValid(string $value): bool
    {
        return strlen($value) < 255;
    }
}
```

If you want a custom exception thrown during construction, override the getException method with your own exception:

```
class Name extends ValueObject
{
    protected function sanitize(string $value): string
    {
        return trim($value);
    }

    public function isValid(string $value): bool
    {
        return strlen($value) < 255;
    }

    protected function getException(): Exception
    {
        return new NameToLongException();
    }
}
```

Examples
--------

[](#examples)

Example implementations can be found at `tests/Unit/ValueObject`. These are the same value objects used for testing:

- [EmailAddress](tests/Unit/ValueObject/EmailAddress.php)
- [Capacity](tests/Unit/ValueObject/Capacity.php)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~385 days

Total

3

Last Release

1469d ago

PHP version history (3 changes)v1.0PHP ^7.1

1.0.1PHP &gt;=7.1

v1.0.2PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6873972?v=4)[Noah van Bochove](/maintainers/noahlvb)[@noahlvb](https://github.com/noahlvb)

---

Top Contributors

[![noahlvb](https://avatars.githubusercontent.com/u/6873972?v=4)](https://github.com/noahlvb "noahlvb (10 commits)")[![LauLaman](https://avatars.githubusercontent.com/u/8283992?v=4)](https://github.com/LauLaman "LauLaman (1 commits)")

---

Tags

dddvaluesOOPvalueobjectsscalar type

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/noahlvb-valueobject/health.svg)

```
[![Health](https://phpackages.com/badges/noahlvb-valueobject/health.svg)](https://phpackages.com/packages/noahlvb-valueobject)
```

###  Alternatives

[prooph/service-bus

PHP Enterprise Service Bus Implementation supporting CQRS and DDD

4421.4M32](/packages/prooph-service-bus)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[prooph/event-sourcing

PHP EventSourcing library

267808.5k17](/packages/prooph-event-sourcing)[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38425.4k](/packages/bocharsky-bw-arrayzy)[phpmentors/domain-kata

Kata for domain models

73426.9k9](/packages/phpmentors-domain-kata)[aura/payload

A Domain Payload implementation.

56370.4k9](/packages/aura-payload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
