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

Leverage Modules in PHP


Until PHP 5.3, modules weren't fully supported. But since the introduction of PHP 5.3, we can use PHP namespaces to implement the module pattern. For historical reasons, we're going to present how namespaces were used before PHP 5.3, but you should strive to use a PHP version that supports PHP namespaces. The best choice is always going to be the latest stable version of PHP.

First-Level Namespacing

A common approach is to use a first-level namespace that identifies your company. This will help in avoiding conflicts with third-party libraries. If you're using PSR-0, you'll have a real folder for the namespace; if you're using PSR-4, you don't need it. We'll go deeper into this shortly. But first, let's take a look at the PHP namespacing conventions.

PEAR-Style Namespacing

Before PHP 5.3, due to the lack of a namespace construction, PEAR-style namespaces were used. PEAR is an acronym for PHP Extension and Application Repository, and in the good old days, it was a Repository...