O'Reilly logo

Modernizing Legacy Applications in PHP by Paul M. Jones

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required