The Clean Architecture in PHP

Aleksandr Shitik
Aleksandr Shitik

I write my own posts and books, and review movies and books. Expert in cosmology and astronomy, IT, productivity, and planning.

The Clean Architecture in PHP
Kristopher Wilson
Genres: Programming
Year of publication: 2015
Year of reading: 2020
My rating: Highest
Number of reads: 1
Total pages: 251
Summary (pages): 6
Original language of publication: English
Translations to other languages: No translations to other languages found

General Information

A 250-page book on building clean architecture in PHP (roughly the same one that Uncle Bob wrote about in his book). Although PHP could easily be replaced with Java, C#, or another older-generation OOP language. The book I came across was in English, so I’m not sure if translations into other languages exist. The book includes code snippets (in color), but almost no images—just a couple of diagrams and flowcharts.

Book Contents

The book consists of 4 sections:

  1. Problems with Code
  2. Toolkits for Solving Problems
  3. Clean (Layered/Onion) Architecture
  4. Examples from Clean Architecture

The section "Problems with Code" explains why code often becomes difficult to read, test, and maintain. Poor architecture is often one of the main reasons.

The second section (on solution tools) consists of several chapters. The first one is about design patterns (including examples of some patterns). Next is a detailed breakdown of the SOLID principles. The following chapter thoroughly covers dependency injection. The author also doesn’t overlook interfaces—this is the next chapter.

The exploration of clean architecture begins with an analysis of the MVC pattern and a description of each of its components. Routing is also discussed, and at the end of the first chapter, the author points out the weaknesses of this architectural approach. After this, the chapters on onion architecture begin, with a detailed breakdown of each component. Each breakdown is accompanied by a PHP code example for a specific layer (more abstract code without deep detailing). A lot of attention is also paid to theoretical aspects and questions, such as why there should be no tight coupling to a database or framework and what role testing plays in such an architecture.

The last section is a kind of summary of the entire book, consolidating all the material above and building a small real-world example with its own folder structure and business model, while using real frameworks and packages.

Opinion

The concept of layered architecture, which Uncle Bob (Robert Martin) would likely approve of, is implemented directly in PHP. Dependency injection, the use of interfaces, the description and implementation of some popular patterns, SOLID, and other approaches to building architecture in PHP. And most importantly—everything is backed by practical examples. Therefore, I can recommend this book for both introduction and in-depth study.

Вверх