Appendix D. Code after Transaction Scripts

This Appendix shows a version of the code from appendices B and C that extracts the domain logic from the page script into a Transactions class. Note how the original page script is now reduced to being a object creation and injection mechanism, and hands off most logic to the Transactions classes. Note also how the $failure, $credits, and $article_types variables are now properties on the Transactions class, and how the normalization/sanitizing logic and credit-calculation logic is part of the Transactions logic.

page_script.php <?php 2 3 // ... $user_id value created earlier 4 5 $db = new Database($db_host, $db_user, $db_pass); 6 $articles_gateway = new ArticlesGateway($db); 7 $users_gateway = new UsersGateway($db); ...

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.