Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/biberlabs/ddd-embeddables
A collection of reusable value objects written in PHP and targeting version 8.0 and above.
https://github.com/biberlabs/ddd-embeddables
ddd-embeddables doctrine-orm domain-driven-design embeddable php
Last synced: 2 months ago
JSON representation
A collection of reusable value objects written in PHP and targeting version 8.0 and above.
- Host: GitHub
- URL: https://github.com/biberlabs/ddd-embeddables
- Owner: biberlabs
- License: mit
- Created: 2016-09-17T11:01:28.000Z (almost 8 years ago)
- Default Branch: develop
- Last Pushed: 2022-10-10T21:20:04.000Z (over 1 year ago)
- Last Synced: 2024-03-26T10:21:23.520Z (3 months ago)
- Topics: ddd-embeddables, doctrine-orm, domain-driven-design, embeddable, php
- Language: PHP
- Homepage:
- Size: 98.6 KB
- Stars: 66
- Watchers: 8
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Lists
- awesome-doctrine - DDD Embeddables - A collection of reusable value objects written in PHP and targeting versions 5.6 and above. (Related Projects)
- awesome-php-value-objects - biberlabs/ddd-embeddables
README
# DDD Embeddables
----
[![Build Status](https://secure.travis-ci.org/biberlabs/ddd-embeddables.svg?branch=master)](https://secure.travis-ci.org/biberlabs/ddd-embeddables)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/biberlabs/ddd-embeddables/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/biberlabs/ddd-embeddables/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/biberlabs/ddd-embeddables/badges/coverage.png?b=master&rand=123)](https://scrutinizer-ci.com/g/biberlabs/ddd-embeddables/?branch=master)A collection of reusable value objects written in PHP and targeting versions 8.0 and above. Value objects are essential building blocks of **Domain Driven Design** approach and described by Martin Fowler in _P of EAA page 486_ as below:
> "Value object is a small simple object, like money or a date range, whose equality isn't based on identity."
> – Martin Fowler
All classes in this library annotated as `ORM\Embeddable` with appropriately adjusted column attributes. This makes them ready to use in any project with Doctrine ORM as [Embeddables](http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/tutorials/embeddables.html).
## Installation & Usage
Install the library using [composer](https://getcomposer.org).```bash
$ composer require biberlabs/ddd-embeddables
```and use it in your entities:
```php
1000
-- OR
SELECT u FROM User u WHERE u.name.surname = :surname
SELECT u FROM User u WHERE u.name.title = :title
```Value objects enables us to write much more cleaner and readable rules when dealing with the domain rules, application-wide. For example:
```php
$username = $user->getEmail()->getLocalpart();
```or
```php
$blacklist = ['spam4me.io', 'foo.com'];
if(in_array($user->getEmail()->getDomain(), $blacklist)) {
// ...
}
```even
```php
if($company->hasMap()) {
$latLng = $company->getAddress()->getGeoPoint()->toArray();
//..
}class Company
{
// ...
/**
* Returns a boolean TRUE if the geolocation of the company is known,
* FALSE otherwise.
*
* @return bool
*/
public function hasMap()
{
return $this->getAddress()->getGeoPoint() !== null;
}
}
```
## Running Tests
You can run unit tests locally via issuing the command below:```bash
$ composer test
```Please make sure that all test are green before creating a PR.
```
PHPUnit 9.5.25 #StandWithUkraine................................................................. 65 / 75 ( 86%)
.......... 75 / 75 (100%)Time: 00:00.037, Memory: 6.00 MB
OK (75 tests, 124 assertions)
```## Contributing
If you want to contribute to **ddd-embeddables** and make it better, your help is very welcome.Please take a look our [CONTRIBUTING.md](CONTRIBUTING.md) before creating a pull request.
## Further Reading
Are you interested in Domain Driven Design? Here is a list of good resources to dig in-depth.- [Value Objects](http://martinfowler.com/bliki/ValueObject.html) - Martin Fowler
- [Separating Concerns using Embeddables](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/embeddables.html) - Doctrine ORM documentation
- [Domain-Driven Design in PHP](https://leanpub.com/ddd-in-php/read) - Leanpub 380 pages e-book.
- [Agregate Componenet Pattern In Action](https://lostechies.com/jimmybogard/2009/02/05/ddd-aggregate-component-pattern-in-action/) - Another good article from 2009
- [Domain Driven Design Concepts in ZF2](https://olegkrivtcov.wordpress.com/2014/03/22/domain-driven-design-ddd-concepts-in-zf2/) - An article written by Oleg Krivtsov in 2014
- [Domain Driven Design Quickly](https://www.infoq.com/minibooks/domain-driven-design-quickly) - A quickly-readable minibook and introduction to the fundamentals of DDD by InfoQ.