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

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

stougeiro/valueobject
=====================

A lightweight Value Object foundation for PHP

v1.0.0(2w ago)041MITPHPPHP &gt;=8.1

Since Jul 27Pushed 2w ago1 watchersCompare

[ Source](https://github.com/stougeiro/valueobject)[ Packagist](https://packagist.org/packages/stougeiro/valueobject)[ RSS](/packages/stougeiro-valueobject/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

[![phpstan-level](https://camo.githubusercontent.com/942bdbddc7b2adea1d63ed80793492d06d72ef41911edcba33310d0745581548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230392d627269676874677265656e)](https://camo.githubusercontent.com/942bdbddc7b2adea1d63ed80793492d06d72ef41911edcba33310d0745581548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230392d627269676874677265656e)

ValueObject
===========

[](#valueobject)

A lightweight and flexible foundation for creating **Value Objects** in PHP.
This package provides a minimalistic interface and an extensible abstract class that help developers build semantic value objects that encourage immutability, with optional validation and a clean factory pattern.

✨ Features
----------

[](#-features)

- **Generic factory**: `create(...$args)`
    Delegates construction to the concrete class while respecting its parameter types and order.
- **Optional validation**: `isValid()`
    Developers decide when and how to validate the underlying value.
- **Semantic comparison**: `equals(ValueObjectInterface $other)`
    Compare two value objects of the same type and value.
- **Consistent value access**: `value()`
    Returns the underlying primitive or structured value.
- **String representation**: `__toString()`
    Ensures every value object can be safely cast to a string.
- **Minimalistic and extensible**
    The interface stays small and expressive, while concrete classes define their own semantics.

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require stougeiro/valueobject
```

🚀 Usage Example
---------------

[](#-usage-example)

### Creating a Value Object

[](#creating-a-value-object)

```
use STDW\ValueObject\ValueObjectAbstracted;

final class Email extends ValueObjectAbstracted
{
    public function __construct(private string $email) {}

    public function value(): mixed
    {
        return $this->email;
    }

    public function isValid(): bool
    {
        return filter_var($this->email, FILTER_VALIDATE_EMAIL) !== false;
    }

    public function __toString__(): string
    {
        return $this->email;
    }
}
```

🚀 Instantiation
---------------

[](#-instantiation)

```
    $email = Email::create('sidney@example.com');

    if ($email->isValid()) {
        echo $email; // sidney@example.com
    }
```

---

🧠 Why Value Objects?
--------------------

[](#-why-value-objects)

Value Objects are a core building block in domain‑driven design and clean architecture. They encapsulate meaning, enforce structure, and prevent primitive obsession — ensuring that values carry behavior and validation instead of floating loosely through the system.

This package aims to provide a simple, expressive and unobtrusive foundation for building your own Value Objects without unnecessary boilerplate.

---

🤝 Contributions
---------------

[](#-contributions)

Contributions are welcome. Feel free to open issues or submit pull requests.

[![](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/stougeiro)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance96

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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 ~881 days

Total

2

Last Release

20d ago

Major Versions

v0.1.0 → v1.0.02026-07-27

PHP version history (2 changes)v0.1.0PHP ^8.1

v1.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3516412?v=4)[S.Tougeiro](/maintainers/stougeiro)[@stougeiro](https://github.com/stougeiro)

---

Top Contributors

[![stougeiro](https://avatars.githubusercontent.com/u/3516412?v=4)](https://github.com/stougeiro "stougeiro (22 commits)")

---

Tags

Value ObjectDomain Driven Designdddclean-arch

### Embed Badge

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

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

###  Alternatives

[phpmentors/domain-kata

Kata for domain models

73455.4k9](/packages/phpmentors-domain-kata)[dykyi-roman/awesome-claude-code

Claude Code extension for PHP: audits (architecture, DDD, security, performance, PSR, design patterns, Docker, CI/CD, tests, docs), 3-level code review, automated bug fix, generators (DDD, CQRS, GoF patterns, PSR, tests, documentation, Docker, CI/CD), code explanation, refactoring. 26 commands, 62 agents, 259 skills.

931.4k](/packages/dykyi-roman-awesome-claude-code)[thejano/laravel-domain-driven-design

Helps to use domain driven design within laravel

15526.0k](/packages/thejano-laravel-domain-driven-design)[phpmentors/domain-commons

Commons for domain models

11308.3k](/packages/phpmentors-domain-commons)[ammardaana/laravel-domain-driven-design

Generate laravel Domain driven design (monolith) structure

102.0k](/packages/ammardaana-laravel-domain-driven-design)

PHPackages © 2026

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