PHPackages                             biig/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. biig/domain

Abandoned → [swag-industries/doctrine-domain-events](/?search=swag-industries%2Fdoctrine-domain-events)Symfony-bundle

biig/domain
===========

v2.1.4(5y ago)1619.9k9[2 issues](https://github.com/biig-io/DomainComponent/issues)[2 PRs](https://github.com/biig-io/DomainComponent/pulls)MITPHPPHP &gt;=7.1CI failing

Since Jan 18Pushed 5y ago5 watchersCompare

[ Source](https://github.com/biig-io/DomainComponent)[ Packagist](https://packagist.org/packages/biig/domain)[ RSS](/packages/biig-domain/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (7)Versions (26)Used By (0)

Domain component
================

[](#domain-component)

[![Build Status](https://camo.githubusercontent.com/65a192c395ac2029530c004420c92888d2b8f1dca269df002f3d677cf587063a/68747470733a2f2f7472617669732d63692e6f72672f626969672d696f2f446f6d61696e436f6d706f6e656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/biig-io/DomainComponent)[![Latest Stable Version](https://camo.githubusercontent.com/b3b9d252403368f32c8866362fa0800e2c95a5fd5dbb24c448c884b29cfb4c07/68747470733a2f2f706f7365722e707567782e6f72672f626969672f646f6d61696e2f762f737461626c65)](https://packagist.org/packages/biig/domain)[![License](https://camo.githubusercontent.com/752361051ac2fd310febaea112ff8578ba567c87d8ab85d61e9961c016abe94e/68747470733a2f2f706f7365722e707567782e6f72672f626969672f646f6d61696e2f6c6963656e7365)](https://packagist.org/packages/biig/domain)

This library is design to help you to build your application with a Domain Design Development approach.

It is well integrated with:

- Symfony &gt;= 4.3 (for &gt;=3.3 compatibility, install the version 1.5 of the domain component)
- ApiPlatform &gt;= 2.1
- Doctrine &gt;=2.5

But you can use it with any PHP project.

[Here are some slides](http://talks.nekland.fr/DoctrineDomainEvents/) that explain how we get there.

Features
--------

[](#features)

Domain Events:

- [Domain event dispatcher](docs/domain_event_dispatcher.md)
- [Injection of the dispatcher in Doctrine entities](docs/injection_in_doctrine_entities.md)
- [Symfony serializer integration](docs/symfony_serializer_integration.md)
- [Learn how do more with our cookbooks](docs/cookbooks.md)

Drawbacks
---------

[](#drawbacks)

This library is build to allow you to use Doctrine models as Domain model. This has some cost: you can't instantiate domain model by hand anymore. This means that you need a factory for any of the usage of your domain model.

This component provides the implementation for Symfony serializer and Doctrine. For your own needs you should use the class (service if you use the bundle) `Biig\Component\Domain\Model\Instantiator\Instantiator`.

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

[](#installation)

```
composer require biig/domain
```

Basic usage
-----------

[](#basic-usage)

```
class YourModel extends DomainModel
{
    public const CREATION = 'creation';
    public function __construct()
    {
        $this->dispatch(new DomainEvent($this), self::CREATION);
    }
}
```

```
class DomainRule implements DomainRuleInterface
{
    public function on()
    {
        return YourModel::CREATION;
    }

    public function execute(DomainEvent $event)
    {
        // Do Something on your model creation
    }
}
```

As your model needs a dispatcher you need to call the `setDispatcher()` method any time you create a new instance of your model. To avoid doing this manually you can use the `Instantiator` that the library provides.

> It doesn't use the constructor to add the dispatcher because in PHP you can create objects without the constructor. For instance, that's what Doctrine does.

Integration to Symfony
----------------------

[](#integration-to-symfony)

Use the bundle :

```
