Chapter 8. Extract SQL statements to Gateways
Now that we have moved all our class-oriented functionality to a central directory location (and have a reasonable test suite for those classes) we can begin extracting more logic from our page scripts and place that logic into classes. This will have two benefits: first, we will be able to keep the various concerns of the application separated; second, we will be able to test the extracted logic so that any breaks will be easy to notice before we deploy into production.
The first of these extractions will be to move all SQL-oriented code to its own set of classes. For our purposes, SQL is a stand-in for any system of reading from and writing to a data store. This may be a no-SQL system, a CSV file, ...
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.