PHPackages                             somnambulist/domain - 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. [Database &amp; ORM](/categories/database)
4. /
5. somnambulist/domain

ActiveLibrary[Database &amp; ORM](/categories/database)

somnambulist/domain
===================

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

7.0.0(1y ago)266.1k↓63.5%28MITPHPPHP &gt;=8.3CI failing

Since Jul 5Pushed 1y ago5 watchersCompare

[ Source](https://github.com/somnambulist-tech/domain)[ Packagist](https://packagist.org/packages/somnambulist/domain)[ RSS](/packages/somnambulist-domain/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (23)Versions (51)Used By (8)

Somnambulist Domain Package
===========================

[](#somnambulist-domain-package)

[![GitHub Actions Build Status](https://camo.githubusercontent.com/154a78ca10333fc9c91d2bffab84e900046d110016c934ff6f2967536ea9d5d1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f6d6e616d62756c6973742d746563682f646f6d61696e2f74657374732e796d6c3f6c6f676f3d676974687562266272616e63683d6d6173746572)](https://github.com/somnambulist-tech/domain/actions?query=workflow%3Atests)[![Issues](https://camo.githubusercontent.com/bf5c1c277f66f9518a340e934c892ddf727ebcd35ab3fc8b007f46fd3158ff0a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f736f6d6e616d62756c6973742d746563682f646f6d61696e3f6c6f676f3d676974687562)](https://github.com/somnambulist-tech/domain/issues)[![License](https://camo.githubusercontent.com/64cfa0b54c08f87520100e405dca47ef322118c16b9846ed9a3e4d48a0c200ab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736f6d6e616d62756c6973742d746563682f646f6d61696e3f6c6f676f3d676974687562)](https://github.com/somnambulist-tech/domain/blob/master/LICENSE)[![PHP Version](https://camo.githubusercontent.com/47cdea09c9ee8f3104399aad8b2160b834fa11f6735babd75cf05b4eabb00871/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736f6d6e616d62756c6973742f646f6d61696e3f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/somnambulist/domain)[![Current Version](https://camo.githubusercontent.com/ea9b86c4f996d818ccdf3bab9ec3ffbd48cd50305bab73b04cf6a0a767729f14/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6d6e616d62756c6973742f646f6d61696e3f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/somnambulist/domain)

Provides a core set of support classes for building domain oriented projects. This library compiles the previously separate domain and mapping libraries into a single project for easier maintenance.

It consists of:

- Commands
    - CommandBus interface / abstract command
    - SF Messenger implementation
- Doctrine
    - Enumeration factories + Type bindings
    - Additional types / type overrides for the Doctrine Type system
    - Abstract Aggregate repository
    - Custom Postgres DQL functions
- Models
    - Contracts - value object interface definitions
    - Types - a collection of value-objects, enumerations, and date helpers
    - AggregateRoot - an aggregate root stub implementation that can raise events
    - AbstractEntity and AbstractEntityCollection - child entities and helper for an aggregate root
- Events
    - EventBus interface / abstract event
    - SF Messenger EventBus implementation
    - Doctrine subscriber that broadcasts onFlush all events from aggregate roots
    - Custom serializer to handle encode/decode when the event class does not exist
- Jobs
    - JobQueue interface / abstract job
    - SF Messenger implementation
- Queries
    - QueryBus interface / abstract query
    - SF Messenger implementation
- default XML mappings for embeddable objects in Doctrine .dcm.xml and Symfony .orm.xml conventions

### Requirements

[](#requirements)

- PHP 8.3+
- mb\_string
- bcmath
- beberlei/assert
- eloquent/enumeration
- somnambulist/collection
- symfony/messenger for the Messenger bus implementations.

### Installation

[](#installation)

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

- composer require somnambulist/domain

### Upgrading from 5.X to 7.X

[](#upgrading-from-5x-to-7x)

From 7.0 PHP 8.3+ is required, additionally, with the move to Doctrine 3.0 there are substantial differences in how repositories are implemented. Instead of using custom repositories, an `AbstractAggregateRepository` has been added that directly calls into Doctrine EntityManager.

`AbstractModelLocator` and `AbstractServiceModelLocator` have been removed as the addition of type-hints prevented the overriding of findBy etc. As these were helpers, they are no longer necessary.

Most model types are now read-only. Several have been changed to native enums (`DistanceUnit`, `AreaUnit`).

Commands and Jobs are now read-only classes. Queries are still writable to keep the meta-data and include support.

### Upgrading from 4.X to 5.X

[](#upgrading-from-4x-to-5x)

From 5.X this project will be re-namespaced to drop `Domain`. 4.X includes a `classmap.php` providing aliases for backwards compatibility.

From 5.0 the QueryBus supports typed response objects. This is an optional feature that provides a built-in mechanism to handle failed queries without trapping exceptions in the calling code.

From 5.0 domain event names are always generated at construction time as `snake_case`.

### Upgrading from 3.X to 4.X

[](#upgrading-from-3x-to-4x)

From 4.X this project was re-namespaced to `Somnambulist\Components\Domain`. Update all references to reflect this change this includes any Doctrine mapping files / annotations.

The Doctrine `AbstractIdentityType` was moved out of the `Identity` namespace to the main `Types`.

### Usage

[](#usage)

See the docs folder for more documentation on each component.

- [Aggregate Root](docs/aggregate-root.md)
- [Domain Events](docs/domain-events.md)
- [Value Objects](docs/value-objects.md)
- [Enumerations](docs/enumerations.md)
- [Enumeration Bridge](docs/doctrine-enum-bridge.md)
- [Doctrine Mapping](docs/doctrine-mappings.md)
- [Symfony Messenger Integration](docs/messenger.md)
- [Using Command Query Separation](docs/cqrs.md)

### Links

[](#links)

- [Doctrine](http://doctrine-project.org)
- [API Bundle](https://github.com/somnambulist-tech/api-bundle)
- [API Client](https://github.com/somnambulist-tech/api-client)
- [Collection](https://github.com/somnambulist-tech/collection)
- [Form Requests](https://github.com/somnambulist-tech/form-request-bundle)
- [Read-Models](https://github.com/somnambulist-tech/read-models)

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance44

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 98.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 ~43 days

Recently: every ~205 days

Total

50

Last Release

440d ago

Major Versions

2.5.1 → 3.0.02020-08-28

3.2.0 → 4.0.02021-01-21

4.7.0 → 5.0.02023-01-13

5.x-dev → 6.0.02024-03-02

6.0.0 → 7.0.02025-04-12

PHP version history (5 changes)1.0.0PHP &gt;=7.2

3.0.0PHP &gt;=7.4

4.0.0PHP &gt;=8.0

5.0.0PHP &gt;=8.1

7.0.0PHP &gt;=8.3

### 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 (86 commits)")[![jasonhofer](https://avatars.githubusercontent.com/u/974242?v=4)](https://github.com/jasonhofer "jasonhofer (1 commits)")

---

Tags

dddddd-cqrsdoctrinedomain-eventsphpsf-messengervalue objectsdddentitiesdomain-eventsenumerationsaggregate-root

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M519](/packages/shopware-core)[jpkleemans/attribute-events

🔥 Fire events on attribute changes of your Eloquent model

332520.3k2](/packages/jpkleemans-attribute-events)[patchlevel/event-sourcing

A lightweight but also all-inclusive event sourcing library with a focus on developer experience

202332.6k12](/packages/patchlevel-event-sourcing)

PHPackages © 2026

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