Book Image

Domain-Driven Design in PHP

By : Keyvan Akbary, Carlos Buenosvinos, Christian Soronellas
Book Image

Domain-Driven Design in PHP

By: Keyvan Akbary, Carlos Buenosvinos, Christian Soronellas

Overview of this book

Domain-Driven Design (DDD) has arrived in the PHP community, but for all the talk, there is very little real code. Without being in a training session and with no PHP real examples, learning DDD can be challenging. This book changes all that. It details how to implement tactical DDD patterns and gives full examples of topics such as integrating Bounded Contexts with REST, and DDD messaging strategies. In this book, the authors show you, with tons of details and examples, how to properly design Entities, Value Objects, Services, Domain Events, Aggregates, Factories, Repositories, Services, and Application Services with PHP. They show how to apply Hexagonal Architecture within your application whether you use an open source framework or your own.
Table of Contents (24 chapters)
Title Page
Credits
Foreword
About the Authors
Acknowledgments
www.PacktPub.com
Customer Feedback
Dedication
Preface
14
Bibliography
15
The End

Spreading the news to Remote Bounded Contexts


In order to communicate a set of Domain Events to local or remote Bounded Contexts, there are two main strategies: messaging and a REST API. The first plans to use a messaging system such as RabbitMQ to transmit the Domain Events. The second plans to create a REST API for accessing the Domain Events of a specific Bounded Context.

Messaging

With all Domain Events persisted into the database, the only thing remaining to spread the news is to push them to our favorite messaging system. We prefer RabbitMQ, but any other system, such as ActiveMQ or ZeroMQ, will do the job. For integrating with RabbitMQ using PHP, there aren't many options, but php-amqplib will do the work.

First of all, we need a service capable of sending persisted Domain Events to RabbitMQ. You may want to query EventStore for all the Events and send each one, which isn't a bad idea. However, we could push the same Domain Event more than once, and generally speaking, we need to minimize...