PHPackages                             glamorous/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. glamorous/value-object

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

glamorous/value-object
======================

Interface to have ValueObjects in your application. An Enum implementing this interface is also available.

2.0(5y ago)117MITPHPPHP &gt;=7.4

Since Jul 1Pushed 4y agoCompare

[ Source](https://github.com/glamorous/value-object)[ Packagist](https://packagist.org/packages/glamorous/value-object)[ RSS](/packages/glamorous-value-object/feed)WikiDiscussions master Synced 3d ago

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

Value Object
============

[](#value-object)

[![Latest Stable Version](https://camo.githubusercontent.com/3a88abffc2d508e9d68ea722332e9fb0f80e6316e04e92aad2d528e0735046af/68747470733a2f2f706f7365722e707567782e6f72672f676c616d6f726f75732f76616c75652d6f626a6563742f762f737461626c65)](https://packagist.org/packages/glamorous/value-object)[![License](https://camo.githubusercontent.com/7f9fb180b857a9e7bc71adeecf92ef81cbd1fd34852bb6efe50fe50b7b707bde/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f676c616d6f726f75732f76616c75652d6f626a6563742e737667)](https://github.com/glamorous/value-object)![PHP Version](https://camo.githubusercontent.com/1173aa5fe17aed138f1ccfdf540924eca11508be6ff3de32def6439be115c7fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f676c616d6f726f75732f76616c75652d6f626a6563742e737667)[![Build Status](https://camo.githubusercontent.com/170cc931e04aac0e5d9315101234fff8fd0365a8a2ce60540337b3cf527f184a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f676c616d6f726f75732f76616c75652d6f626a6563742e737667)](https://travis-ci.com/glamorous/value-object)[![Codecov](https://camo.githubusercontent.com/e0f26cd8efc0f38aaec30e3faa328346204d44434eee34e142a69c2c9ce0c3a3/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f676c616d6f726f75732f76616c75652d6f626a6563742e737667)](https://codecov.io/gh/glamorous/value-object)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/08a4a86abe22c2a804ad858c8dc655e572b73cff31ae5957781eee085b020eae/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f676c616d6f726f75732f76616c75652d6f626a6563742f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/glamorous/value-object/)[![Total Downloads](https://camo.githubusercontent.com/d685d923f5ec3962ecf355a10cc0eadbe655e9ad19c281a9742377657934e5f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676c616d6f726f75732f76616c75652d6f626a6563742e737667)](https://packagist.org/packages/glamorous/value-object)[![GitHub issues](https://camo.githubusercontent.com/5e44fe3200add7e62c774bd5bb3ed4ab5e0255eca8cd6013377b9e967f707c28/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f676c616d6f726f75732f76616c75652d6f626a6563742e737667)](https://github.com/glamorous/value-object/issues)

PHP Interface to create value objects to use in your project. Abstract Enum class available that uses the same interface.

Why?
----

[](#why)

ValueObjects are the ideal way to use in your project. You can force yourself in your project to have data in the way you want.

Documentation
-------------

[](#documentation)

### The interface

[](#the-interface)

The interface has three methods you need to implement.

- **\_\_toString()**: This magic method is needed to represent the ValueObject as a string. Is usefull for logging.
- **toNative()**: This method must return an array, integer, string... This is needed to test if two value objects are the same or not and for serializing.
- **equalsTo(ValueObject $object)**: The method requires another ValueObject instance. The `toNative()`-method can be used to check if two value objects are the same. In the Enum it uses the `equals` method from the parent.

### The Enum

[](#the-enum)

The included Enum extends the Enum from [MyCLabs](https://github.com/myclabs/php-enum). Additionally it implements the interface. This way it's possible to use the functions `toNative()` and `equalsTo()` in your application. More importantly an enumaration is also a value object, something that can't be changed when created. When all those classes implements the same interface, its easier for the developer to use them through eachother.

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

[](#installation)

You can install the package via composer:

```
$ composer require glamorous/value-object
```

Usage
-----

[](#usage)

**Amount (Interface example)**

Most of the people will say: "this is an integer, why do we need a value object?". Then you should read some articles about value objects again.

```

use Glamorous\ValueObject;

final class Amount implements ValueObject
{
    private $amount;

    public __construct(int $amount)
    {
        if ($amount < 0) {
            throw new \InvalidArgumentException('Amount must be above zero or zero');
        }

        $this->amount = $amount;
    }
}

```

**Status (Enum example)**

```
use Glamorous\Enum;

final class Status extends Enum
{
    const OPEN = 'open';
    const CLOSED = 'closed';
}

```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details. To see a list of the contributors: [all contributors](../../contributors).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity64

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

Total

3

Last Release

1830d ago

Major Versions

1.0.1 → 2.02021-05-10

PHP version history (2 changes)1.0.0PHP &gt;=7.0

2.0PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/62723?v=4)[Jonas De Smet](/maintainers/glamorous)[@glamorous](https://github.com/glamorous)

---

Top Contributors

[![glamorous](https://avatars.githubusercontent.com/u/62723?v=4)](https://github.com/glamorous "glamorous (23 commits)")

---

Tags

enumphpvalueobject

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/glamorous-value-object/health.svg)

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

###  Alternatives

[sylius/refund-plugin

Plugin provides basic refunds functionality for Sylius application.

691.7M14](/packages/sylius-refund-plugin)[seboettg/citeproc-php

Full-featured CSL processor (https://citationstyles.org)

761.2M19](/packages/seboettg-citeproc-php)[timeweb/phpstan-enum

Enum class reflection extension for PHPStan

443.2M21](/packages/timeweb-phpstan-enum)[php-unit-conversion/php-unit-conversion

A fully PSR-4 compatible PHP library for converting between standard units of measure.

681.2M1](/packages/php-unit-conversion-php-unit-conversion)[open-feature/sdk

PHP implementation of the OpenFeature SDK

39514.9k15](/packages/open-feature-sdk)

PHPackages © 2026

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