
Modernizing Legacy Applications in PHP
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
All prices
More details
Person
Paul M. Jones is an internationally recognized PHP expert who has worked as everything from junior developer to VP of Engineering in all kinds of organizations (corporate, military, non-profit, educational, medical, and others). He blogs professionally at www.paul-m-jones.com and is a regular speaker at various PHP conferences. Paul's latest open-source project is Aura for PHP. Previously, he was the architect behind the Solar Framework, and was the creator of the Savant template system. He was a founding contributor to the Zend Framework (the DB, DB_Table, and View components), and has written a series of authoritative benchmarks on dynamic framework performance. Paul was one of the first elected members of the PEAR project. He is a voting member of the PHP Framework Interoperability Group, where he shepherded the PSR-1 Coding Standard and PSR-2 Coding Style recommendations, and was the primary author on the PSR-4 Autoloader recommendation. He was also a member of the Zend PHP 5.3 Certification education advisory board. In a previous career, Paul was an operations intelligence specialist for the US Air Force. In his spare time, he enjoys putting.308 holes in targets at 400 yards.
Content
- Cover
- Copyright
- Credits
- Foreword
- About the Author
- Acknowledgement
- www.PacktPub.com
- Table of Contents
- Preface
- Chapter 1: Legacy Applications
- The typical PHP application
- File Structure
- Page Scripts
- Rewrite or Refactor?
- The Pros and Cons of Rewriting
- Why Don't Rewrites Work?
- The Context-switching problem
- The Knowledge problem
- The Schedule Problem
- Iterative Refactoring
- Legacy Frameworks
- Framework-based Legacy Applications
- Refactoring to a Framework
- Review and next steps
- Chapter 2: Prerequisites
- Revision control
- PHP version
- Editor/IDE
- Style Guide
- Test suite
- Review and next steps
- Chapter 3: Implement an Autoloader
- PSR-0
- A Single Location for Classes
- Add Autoloader Code
- As a Global Function
- As a Closure
- As a Static or Instance method
- Using The __autoload() Function
- Autoloader Priority
- Common Questions
- What If I Already Have An Autoloader?
- What are the Performance Implications Of Autoloading?
- How Do Class Names Map To File Names?
- Review and next steps
- Chapter 4: Consolidate Classes and Functions
- Consolidate Class Files
- Find a candidate include
- Move the class file
- Remove the related include calls
- Spot check the codebase
- Commit, Push, Notify QA
- Do ... While
- Consolidate functions into class files
- Find a candidate include
- Convert the function file to a class file
- Change function calls to static method calls
- Spot check the static method calls
- Move the class file
- Do ... While
- Common Questions
- Should we remove the autoloader include call?
- How should we pick files for candidate include calls?
- What if an include defines more than one class?
- What if the one-class-per-file rule is disagreeable?
- What if a Class or Function is defined inline?
- What if a definition file also executes logic?
- What if two classes have the same name?
- What about third-party libraries?
- What about system-wide libraries?
- For functions, can we use instance methods instead of static methods?
- Can we automate this process?
- Review and next steps
- Chapter 5: Replace global With Dependency Injection
- Global Dependencies
- The replacement process
- Find a global variable
- Convert global variables to properties
- Spot check the class
- Convert global properties to constructor parameters
- Convert instantiations to use parameters
- Spot check, Commit, Push, Notify QA
- Do ... While
- Common Questions
- What if we find a global in a static method?
- Is there an alternative conversion process?
- What about class names in variables?
- What about superglobals?
- What about $GLOBALS?
- Review and next steps
- Chapter 6: Replace new with Dependency Injection
- Embedded instantiation
- The replacement process
- Find a new keyword
- Extract One-Time creation to dependency injection
- Extract repeated creation to factory
- Change instantiation calls
- Spot Check, Commit, Push, Notify QA
- Do ... While
- Common Questions
- What About Exceptions and SPL Classes?
- What about Intermediary Dependencies?
- Isn't this a lot of code?
- Should a factory create collections?
- Can we automate all these Injections?
- Review and next steps
- Chapter 7: Write Tests
- Fighting test resistance
- The way of Testivus
- Setting up a test suite
- Install PHPUnit
- Create a tests/ directory
- Pick a class to test
- Write a test case
- Do ... While
- Common Questions
- Can we skip this step and do it later?
- Come On, Really, Can We Do This Later?
- What about hard-to-test classes?
- What about our earlier characterization tests?
- Should we test private and protected methods?
- Can we change a test after we write it?
- Do we need to test Third-party libraries?
- What about code coverage?
- Review and next steps
- Chapter 8: Extract SQL statements to Gateways
- Embedded SQL Statements
- The extraction process
- Search for SQL statements
- Move SQL to a Gateway class
- Namespace and Class names
- Method names
- An initial Gateway class method
- Defeating SQL Injection
- Write a test
- Replace the original code
- Test, Commit, Push, Notify QA
- Do ... While
- Common Questions
- What about INSERT, UPDATE, and DELETE Statements?
- What about Repetitive SQL strings?
- What about complex query strings?
- What about queries inside non-Gateway classes?
- Can we extend from a base Gateway class?
- What about multiple queries and complex result structures?
- What if there is no Database Class?
- Review and next steps
- Chapter 9: Extract Domain Logic to Transactions
- Embedded Domain Logic
- Domain logic patterns
- The Extraction Process
- Search for uses of Gateway
- Discover and Extract Relevant Domain Logic
- Example Extraction
- Spot check the remaining original code
- Write tests for the extracted transactions
- Spot check again, Commit, Push, Notify QA
- Do ... While
- Common Questions
- Are we talking about SQL transactions?
- What about repeated Domain Logic?
- Are printing and echoing part of Domain Logic?
- Can a transaction be a class instead of a Method?
- What about Domain Logic in Gateway classes?
- What about Domain logic embedded in Non-Domain classes?
- Review and next steps
- Chapter 10: Extract Presentation Logic to View Files
- Embedded presentation logic
- The Extraction process
- Search for Embedded presentation logic
- Rearrange the Page script and Spot Check
- Extract Presentation to View file and Spot Check
- Create a views/ Directory
- Add Proper Escaping
- Write View File Tests
- The tests/views/ directory
- Commit, Push, Notify QA
- Do ... While
- Common Questions
- What about Headers and Cookies?
- What if we already have a Template system?
- What about Streaming Content?
- What if we have lots of Presentation variables?
- What about class methods that generate output?
- What about Business Logic Mixed into the presentation?
- What if a page contains only presentation logic?
- Review and next steps
- Chapter 11: Extract Action Logic to Controllers
- Embedded action logic
- The Extraction Process
- Search for Embedded Action Logic
- Rearrange the Page Script and Spot Check
- Identify Code Blocks
- Move Code to Its Related Block
- Spot Check the Rearranged Code
- Extract a Controller Class
- Pick a Class Name
- Create a Skeleton Class File
- Move the Action Logic and Spot Check
- Convert Controller to Dependency Injection and Spot Check
- Write a Controller Test
- Commit, Push, Notify QA
- Do ... While
- Common Questions
- Can we pass parameters to the Controller method?
- Can a Controller have Multiple actions?
- What If the Controller contains include Calls?
- Review and next steps
- Chapter 12: Replace Includes in Classes
- Embedded include Calls
- The Replacement process
- Search for include Calls
- Replacing a Single include Call
- Replacing Multiple include Calls
- Copy include file to Class Method
- Replace the original include Call
- Discover coupled variables through testing
- Replace other include Calls and Test
- Delete the include file and test
- Write a test and refactor
- Convert to Dependency Injection and test
- Commit, Push, Notify QA
- Do ... While
- Common Questions
- Can one class receive logic from many include files?
- What about include calls originating in non-class files?
- Review and next steps
- Chapter 13: Separate Public and Non-Public Resources
- Intermingled resources
- The separation process
- Coordinate with operations personnel
- Create a document root directory
- Reconfigure the server
- Move public resources
- Commit, push, coordinate
- Common Questions
- Is This Really Necessary?
- Review and next steps
- Chapter 14: Decouple URL Paths from File Paths
- Coupled Paths
- The Decoupling Process
- Coordinate with Operations
- Add a Front Controller
- Create a pages/ Directory
- Reconfigure the Server
- Spot check
- Move Page scripts
- Commit, Push, Coordinate
- Common Questions
- Did we really Decouple the Paths?
- Review and next steps
- Chapter 15: Remove Repeated Logic in Page Scripts
- Repeated logic
- The Removal Process
- Modify the Front controller
- Remove Logic from Page Scripts
- Spot Check, Commit, Push, Notify QA
- Common Questions
- What if the Setup Work Is Inconsistent?
- What if we used inconsistent naming?
- Review and next steps
- Chapter 16: Add a Dependency Injection Container
- What is a Dependency Injection Container?
- Adding a DI Container
- Add a DI Container Include File
- Add a Router Service
- Modify the Front Controller
- Extract Page Scripts to Services
- Do ... While
- Remove pages/, Commit, Push, Notify QA
- Common Questions
- How can we refine our service definitions?
- What if there are includes In the Page Script?
- Can we reduce the size of the services.php file?
- Can we reduce the size of the router service?
- What if we cannot update to PHP 5.3?
- Review and next steps
- Chapter 17: Conclusion
- Opportunities for improvement
- Conversion to Framework
- Review and next steps
- Appendix A: Typical Legacy Page Script
- Appendix B: Code before Gateways
- Appendix C: Code after Gateways
- Appendix D: Code after Transaction Scripts
- Appendix E: Code before Collecting Presentation Logic
- Appendix F: Code after Collecting Presentation Logic
- Appendix G: Code after Response View File
- Appendix H: Code after Controller Rearrangement
- Appendix I: Code after Controller Extraction
- Appendix J: Code after Controller Dependency Injection
- Index
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.
File format: PDF
Copy-Protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (only limited: Kindle).
The file format PDF always displays a book page identically on any hardware. This makes PDF suitable for complex layouts such as those used in textbooks and reference books (images, tables, columns, footnotes). Unfortunately, on the small screens of e-readers or smartphones, PDFs are rather annoying, requiring too much scrolling.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our eBook Help page.