PHPackages                             somnambulist/value-objects - 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. somnambulist/value-objects

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

somnambulist/value-objects
==========================

A simple value-object implementation for use in Entities. Includes a couple of basic types.

1.4.0(7y ago)13.6kMITPHPPHP &gt;=7

Since Jun 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/dave-redfern/somnambulist-value-objects)[ Packagist](https://packagist.org/packages/somnambulist/value-objects)[ RSS](/packages/somnambulist-value-objects/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (11)Used By (0)

Moved to
==============================================================

[](#moved-to-httpsgithubcomdave-redfernsomnambulist-domain)

This repository has been archived. Please update to the combined package.s

Value Objects Library
---------------------

[](#value-objects-library)

Value Objects (VOs) are Immutable domain objects that represent some value in your domain model but without a thread of continuous identity i.e. their identity is through their properties. VOs allow your entities to encapsulate properties and provide type safety.

This library provides an abstract base class that provides a basic equality test and foundation for your VOs along with a couple of basic types. As VOs form part of YOUR domain, you should implement the VOs that you need for your domain, following your domain naming (e.g. if you do not call an email address an EmailAddress then create your own VO for that purpose).

VOs should be self-validating during construction. For this purpose, the Assertion library by Benjamin Eberlei is used, however you may wish to use another or filter\_var() etc directly.

If you see something missing or have suggestions for other methods, submit a PR or ticket.

### Requirements

[](#requirements)

- PHP 7+
- mb\_string
- beberlei/assert
- eloquent/enumeration
- somnambulist/collection

### Installation

[](#installation)

Install using composer, or checkout / pull the files from github.com.

- composer require somnambulist/value-objects

### Usage

[](#usage)

Extend the abstract value object and implement the single required method toString(). The default equality method (equals()) uses reflection on the VO properties and compares them directly - only between VO types.

For example:

```
use Assert\Assert;
use Somnambulist\ValueObjects\AbstractValueObject;

class Uuid extends AbstractValueObject
{

    /**
     * @var string
     */
    private $uuid;

    /**
     * Constructor.
     *
     * @param string $uuid
     */
    public function __construct(string $uuid)
    {
        Assert::that($uuid, null, 'uuid')->notEmpty()->uuid();

        $this->uuid = $uuid;
    }

    /**
     * @return string
     */
    public function toString(): string
    {
        return $this->uuid;
    }
}

$uuid = new Uuid(\Ramsey\Uuid\Uuid::uuid4());
```

#### Usage with Doctrine

[](#usage-with-doctrine)

These VOs may be used with Doctrine as Embeddable objects - however if you allow the VO to be null, it will be instantiated empty so your methods / toString() should handle that case e.g.:

A User has a nullable Profile VO, when Doctrine hydrates the User, the Profile VO will also be hydrated but empty, so if the Profile has a nickname() or avatar() method, these must support returning null and your toString() method must cast null to a string to avoid type errors.

### Links

[](#links)

- [Doctrine](http://doctrine-project.org)
- [Enumeration Bridge](https://github.com/dave-redfern/somnambulist-doctrine-enum-bridge)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~62 days

Recently: every ~128 days

Total

10

Last Release

2683d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c0e439bf91b68c2e81e0250c752d3a552e78752c91acdf00c72a1f93aeb1ceca?d=identicon)[dredfern](/maintainers/dredfern)

---

Top Contributors

[![dave-redfern](https://avatars.githubusercontent.com/u/1477147?v=4)](https://github.com/dave-redfern "dave-redfern (3 commits)")

---

Tags

domain-driven-designvalue-objectvalue objectsdddentitiesdomain-events

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/somnambulist-value-objects/health.svg)

```
[![Health](https://phpackages.com/badges/somnambulist-value-objects/health.svg)](https://phpackages.com/packages/somnambulist-value-objects)
```

###  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)[somnambulist/domain

Provides a collection of entities, helpers and base implementations for creating domain objects.

265.8k8](/packages/somnambulist-domain)[prooph/event-sourcing

PHP EventSourcing library

267808.5k17](/packages/prooph-event-sourcing)[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)
