Book Image

Modernizing Legacy Applications in PHP

By : Paul Jones
Book Image

Modernizing Legacy Applications in PHP

By: Paul Jones

Overview of this book

Have you noticed that your legacy PHP application is composed of page scripts placed directly in the document root of the web server? Or, do your page scripts, along with any other classes and functions, combine the concerns of model, view, and controller into the same scope? Is the majority of the logical flow incorporated as include files and global functions rather than class methods? Working with such a legacy application feels like dragging your feet through mud, doesn’t it?This book will show you how to modernize your application in terms of practice and technique, rather than in terms of using tools such as frameworks and libraries, by extracting and replacing its legacy artifacts. We will use a step-by-step approach, moving slowly and methodically, to improve your application from the ground up. We’ll show you how dependency injection can replace both the new and global dependencies. We’ll also show you how to change the presentation logic to view files and the action logic to a controller. Moreover, we’ll keep your application running the whole time. Each completed step in the process will keep your codebase fully operational with higher quality. When we are done, you will be able to breeze through your code like the wind. Your code will be autoloaded, dependency-injected, unit-tested, layer-separated, and front-controlled. Most of the very limited code we will add to your application is specific to this book. We will be improving ourselves as programmers, as well as improving the quality of our legacy application.
Table of Contents (35 chapters)
Modernizing Legacy Applications in PHP
Credits
Foreword
About the Author
Acknowledgement
www.PacktPub.com
Preface
Typical Legacy Page Script
Code before Gateways
Code after Gateways
Code after Transaction Scripts
Code before Collecting Presentation Logic
Code after Collecting Presentation Logic
Code after Response View File
Code after Controller Rearrangement
Code after Controller Extraction
Code after Controller Dependency Injection
Index

Review and next steps


At this point, we have made a big step forward in modernizing our legacy application. We have begun converting from an include-oriented architecture to a class-oriented one. Even if we later discover a class or function that we missed, that's OK; we can follow the above process as many times as needed until all definitions have been moved to the central location.

We may still have lots of include statements in the application, but those that remain are related to the application flow, and not to pulling in class and function definitions. Any include calls that remain are executing logic. We can now see the flow of the application much better.

We have put in place a structure for new functionality. Any time we need to add a new behavior, we can place it in a new class, and that class will be autoloaded whenever we need it. We can stop writing new stand-alone functions; instead, we will write new methods on classes. These new methods will be much more amenable to unit tests...