https://github.com/jgimeno/value-objects
Ultimate Collection of PHP Value Objects to use on your projects.
https://github.com/jgimeno/value-objects
domain-driven-design php7 value-object
Last synced: 8 months ago
JSON representation
Ultimate Collection of PHP Value Objects to use on your projects.
- Host: GitHub
- URL: https://github.com/jgimeno/value-objects
- Owner: jgimeno
- License: mit
- Created: 2017-02-14T19:53:28.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-27T16:26:33.000Z (almost 9 years ago)
- Last Synced: 2025-06-03T18:30:21.326Z (8 months ago)
- Topics: domain-driven-design, php7, value-object
- Language: PHP
- Homepage:
- Size: 61.5 KB
- Stars: 7
- Watchers: 0
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://travis-ci.org/jgimeno/value-objects)
[](https://coveralls.io/github/jgimeno/value-objects?branch=master)
[](https://codeclimate.com/github/jgimeno/value-objects)
# Ultimate PHP Value Object Collection
Collection of PHP value objects to use and extend as building blocks for DDD.
This library comes with the idea of having a starting point for defining
value objects for different projects.
All the value objects are inmutable.
## How to install
You can get it using composer:
composer require jgimeno/value-objects
## How to use
### Base objects
The idea of this library is to have a collection of objects as a
base for the creation of your Domain.
The most basic object is the `ValueObject` which we can extend all
the value objects we want to create from.
Base `ValueObject` implements `__toString()` and `equals()` methods (i.e. you get them
for free).
If we know that our value objects will benefit from the methods included in the
objects `Strings`, `Number` or `Boolean`, we can extend from there.
### Rationale
Imagine that I create an object called `SonName` that our domain needs.
In that case it could be useful to extend from `Strings` and we will
have methods like `toUpperCase()`, `trim()`, etc that we can reuse.
You get the idea.
Lastly there is another base object called `Identifier`. This is useful when
creating ids, for example, a `UserId` can extend from `Identifier`.
Then we can do `UserId::generate()` and we will have a unique
`userId` generated using UUIDs.
### Useful objects
`Internet\Email`: Object representing an email address, it throws exceptions
when given email is not a valid email.
`Internet\IpAddress`: Object that represents an IP address, it throws exception
when is not a valid ip address.