Review and next steps

With this step, we have reduced our page scripts to a bare core of logic. All they do now is set up dependencies for, and then create, a controller object. The front controller does everything before that, and everything after.

As it happens, even this logic can be extracted from the page scripts. An object called a dependency injection container can receive the object creation logic as series of closures, one closure per page script. The container can handle the object creation for us and we can remove the page scripts entirely.

Thus, our final refactoring will extract all object creation logic to a dependency injection container. We will also modify our front controller to instantiate controller objects instead of requiring ...

Get Modernizing Legacy Applications in PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.