Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Modernizing Legacy Applications in PHP
  • Table Of Contents Toc
Modernizing Legacy Applications in PHP

Modernizing Legacy Applications in PHP

By : Paul Jones
5 (6)
close
close
Modernizing Legacy Applications in PHP

Modernizing Legacy Applications in PHP

5 (6)
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 (29 chapters)
close
close
Preface
18
A. Typical Legacy Page Script
19
B. Code before Gateways
20
C. Code after Gateways
21
D. Code after Transaction Scripts
chevron up
22
E. Code before Collecting Presentation Logic
23
F. Code after Collecting Presentation Logic
24
G. Code after Response View File
25
H. Code after Controller Rearrangement
26
I. Code after Controller Extraction
27
J. Code after Controller Dependency Injection
28
Index

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);
8 $article_transactions = new ArticleTransactions(
9 $articles_gateway,
10 $users_gateway
11 );
12
13 if ($_POST['id']) {
14 $article_transactions->updateExistingArticle($user_id, $_POST);
15 } else {
16 ...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Modernizing Legacy Applications in PHP
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon