{"id":23434919,"url":"https://github.com/gpslab/domain-event","last_synced_at":"2025-04-13T03:20:00.248Z","repository":{"id":62512147,"uuid":"69552555","full_name":"gpslab/domain-event","owner":"gpslab","description":"Library to create the domain layer of your DDD application","archived":false,"fork":false,"pushed_at":"2019-12-23T07:59:48.000Z","size":213,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T20:21:18.606Z","etag":null,"topics":["ddd","domain-event","infrastructure","php","predis","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gpslab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-29T09:27:56.000Z","updated_at":"2024-10-10T09:31:34.000Z","dependencies_parsed_at":"2022-11-02T13:16:45.592Z","dependency_job_id":null,"html_url":"https://github.com/gpslab/domain-event","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fdomain-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fdomain-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fdomain-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fdomain-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpslab","download_url":"https://codeload.github.com/gpslab/domain-event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248658263,"owners_count":21140913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ddd","domain-event","infrastructure","php","predis","symfony"],"created_at":"2024-12-23T12:33:55.504Z","updated_at":"2025-04-13T03:20:00.229Z","avatar_url":"https://github.com/gpslab.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://img.shields.io/packagist/v/gpslab/domain-event.svg?maxAge=3600\u0026label=stable)](https://packagist.org/packages/gpslab/domain-event)\n[![PHP from Travis config](https://img.shields.io/travis/php-v/gpslab/domain-event.svg?maxAge=3600)](https://packagist.org/packages/gpslab/domain-event)\n[![Total Downloads](https://img.shields.io/packagist/dt/gpslab/domain-event.svg?maxAge=3600)](https://packagist.org/packages/gpslab/domain-event)\n[![Build Status](https://img.shields.io/travis/gpslab/domain-event.svg?maxAge=3600)](https://travis-ci.org/gpslab/domain-event)\n[![Coverage Status](https://img.shields.io/coveralls/gpslab/domain-event.svg?maxAge=3600)](https://coveralls.io/github/gpslab/domain-event?branch=master)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/gpslab/domain-event.svg?maxAge=3600)](https://scrutinizer-ci.com/g/gpslab/domain-event/?branch=master)\n[![StyleCI](https://styleci.io/repos/69552555/shield?branch=master)](https://styleci.io/repos/69552555)\n[![License](https://img.shields.io/packagist/l/gpslab/domain-event.svg?maxAge=3600)](https://github.com/gpslab/domain-event)\n\nDomain event\n============\n\nLibrary to create the domain layer of your [Domain-driven design (DDD)](https://en.wikipedia.org/wiki/Domain-driven_design) application\n\n## Installation\n\nPretty simple with [Composer](http://packagist.org), run:\n\n```sh\ncomposer require gpslab/domain-event\n```\n\n## Base usage\n\nCreate a domain event\n\n```php\nuse GpsLab\\Domain\\Event\\Event;\n\nfinal class PurchaseOrderCreatedEvent implements Event\n{\n    private $customer_id;\n\n    private $create_at;\n\n    public function __construct(CustomerId $customer_id, \\DateTimeImmutable $create_at)\n    {\n        $this-\u003ecustomer_id = $customer_id;\n        $this-\u003ecreate_at = $create_at;\n    }\n\n    public function customerId()\n    {\n        return $this-\u003ecustomer_id;\n    }\n\n    public function createAt()\n    {\n        return $this-\u003ecreate_at;\n    }\n}\n```\n\nRaise your event\n\n```php\nuse GpsLab\\Domain\\Event\\Aggregator\\AbstractAggregateEvents;\n\nfinal class PurchaseOrder extends AbstractAggregateEventsRaiseInSelf\n{\n    private $customer_id;\n\n    private $create_at;\n\n    public function __construct(CustomerId $customer_id)\n    {\n        $this-\u003eraise(new PurchaseOrderCreatedEvent($customer_id, new \\DateTimeImmutable()));\n    }\n\n    /**\n     * The raise() method will automatically call this method.\n     * Since it's an event you should never do some tests in this method.\n     * Try to think that an Event is something that happened in the past.\n     * You can not modify what happened. The only thing that you can do is create another event to compensate.\n     * You do not obliged to listen this event and are not required to create this method.\n     */\n    protected function onPurchaseOrderCreated(PurchaseOrderCreatedEvent $event)\n    {\n        $this-\u003ecustomer_id = $event-\u003ecustomerId();\n        $this-\u003ecreate_at = $event-\u003ecreateAt();\n    }\n}\n```\n\nCreate listener\n\n```php\nclass SendEmailOnPurchaseOrderCreated\n{\n    private $mailer;\n\n    public function __construct($mailer)\n    {\n        $this-\u003emailer = $mailer;\n    }\n\n    public function __invoke(PurchaseOrderCreatedEvent $event)\n    {\n        $this-\u003emailer-\u003esend('recipient@example.com', sprintf(\n            'Purchase order created at %s for customer #%s',\n            $event-\u003ecreateAt()-\u003eformat('Y-m-d'),\n            $event-\u003ecustomerId()\n        ));\n    }\n}\n```\n\nDispatch events\n\n```php\nuse GpsLab\\Domain\\Event\\Bus\\ListenerLocatedEventBus;\nuse GpsLab\\Domain\\Event\\Listener\\Locator\\DirectBindingEventListenerLocator;\n\n// first the locator\n$locator = new DirectBindingEventListenerLocator();\n// you can use several listeners for one event and one listener for several events\n$locator-\u003eregister(PurchaseOrderCreatedEvent::class, new SendEmailOnPurchaseOrderCreated(/* $mailer */));\n\n// then the event bus\n$bus = new ListenerLocatedEventBus($locator);\n\n// do what you need to do on your Domain\n$purchase_order = new PurchaseOrder(new CustomerId(1));\n\n// this will clear the list of event in your AggregateEvents so an Event is trigger only once\n$bus-\u003epullAndPublish($purchase_order);\n```\n\n## Documentation\n\n* [Base usage](docs/base.md)\n* [Raise events in self](docs/raise_in_self.md)\n* Listener\n  * [Create listener](docs/listener/listener.md)\n  * [Create subscriber](docs/listener/subscriber.md)\n  * Locator\n    * [Direct binding locator](docs/listener/locator/direct_binding.md)\n    * [PSR-11 Container locator](docs/listener/locator/psr-11_container.md) *([PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*\n    * [Symfony container locator](docs/listener/locator/symfony_container.md) *(Symfony 3.3 [implements](http://symfony.com/blog/new-in-symfony-3-3-psr-11-containers) a [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*\n* [Queue](docs/queue/queue.md)\n  * [Queue event bus](docs/queue/bus.md)\n  * [Pull](docs/queue/pull/pull.md)\n    * [Memory queue](docs/queue/pull/memory.md)\n    * [Predis queue](docs/queue/pull/predis.md)\n  * [Subscribe](docs/queue/subscribe/subscribe.md)\n    * [Executing queue](docs/queue/subscribe/executing.md)\n    * [AMQP queue](docs/queue/subscribe/amqp.md)\n    * [Predis queue](docs/queue/subscribe/predis.md)\n  * Serialize command\n    * [Simple payload serializer](docs/queue/serialize/simple.md)\n    * [Optimized Symfony serializer](docs/queue/serialize/optimized.md)\n    * [Payload Symfony serializer](docs/queue/serialize/payload.md)\n* Frameworks\n  * [Symfony bundle](https://github.com/gpslab/domain-event-bundle)\n* [Middleware](https://github.com/gpslab/middleware)\n* [Payload](https://github.com/gpslab/payload)\n\n## License\n\nThis bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpslab%2Fdomain-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpslab%2Fdomain-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpslab%2Fdomain-event/lists"}