售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
PHP 7: Real World Application Development
Table of Contents
PHP 7: Real World Application Development
PHP 7: Real World Application Development
Credits
Preface
What this learning path covers
What you need for this learning path
Who this learning path is for
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Module 1
1. Building a Foundation
Introduction
PHP 7 installation considerations
How to do it...
Installing directly from source
Installing PHP 7 from pre-compiled binaries
Installing a *AMP package
There's more...
See also
Using the built-in PHP web server
How to do it...
Defining a test MySQL database
How to do it...
Installing PHPUnit
Implementing class autoloading
Getting ready
How to do it...
How it works...
Hoovering a website
How to do it...
How it works...
See also
Building a deep web scanner
How to do it...
How it works...
See also
Creating a PHP 5 to PHP 7 code converter
Getting ready
How to do it...
How it works...
See also
2. Using PHP 7 High Performance Features
Introduction
Understanding the abstract syntax tree
How to do it...
How it works...
See also
Understanding differences in parsing
How to do it...
How it works...
See also
Understanding differences in foreach() handling
How to do it...
How it works...
See also
Improving performance using PHP 7 enhancements
How to do it...
How it works...
There's more...
Iterating through a massive file
How to do it...
How it works...
Uploading a spreadsheet into a database
Getting ready...
How to do it...
How it works...
Recursive directory iterator
How to do it...
How it works...
3. Working with PHP Functions
Introduction
Developing functions
How to do it...
How it works...
Hinting at data types
How to do it...
How it works...
See also
Using return value data typing
How to do it...
How it works...
There's more...
See also
Using iterators
How to do it...
How it works...
Writing your own iterator using generators
How to do it...
How it works...
4. Working with PHP Object-Oriented Programming
Introduction
Developing classes
How to do it...
How it works...
See also...
Extending classes
How to do it...
How it works...
Using static properties and methods
How to do it...
How it works...
See also
Using namespaces
How to do it...
How it works...
Defining visibility
How to do it...
How it works...
See also
Using interfaces
How to do it...
How it works...
Using traits
How to do it...
How it works...
Implementing anonymous classes
How to do it...
How it works...
5. Interacting with a Database
Introduction
Using PDO to connect to a database
How to do it...
How it works...
See also
Building an OOP SQL query builder
How to do it...
How it works...
See also
Handling pagination
How to do it...
How it works...
See also
Defining entities to match database tables
How to do it...
How it works...
See also
Tying entity classes to RDBMS queries
How to do it...
How it works...
There's more...
Embedding secondary lookups into query results
How to do it...
How it works...
Implementing jQuery DataTables PHP lookups
How to do it...
How it works...
There's more...
6. Building Scalable Websites
Introduction
Creating a generic form element generator
How to do it...
How it works...
Creating an HTML radio element generator
How to do it...
How it works...
There's more...
Creating an HTML select element generator
How to do it...
How it works...
Implementing a form factory
How to do it...
How it works...
Chaining $_POST filters
How to do it...
How it works...
There's more...
See also
Chaining $_POST validators
How to do it...
How it works...
Tying validation to a form
How to do it...
How it works...
7. Accessing Web Services
Introduction
Converting between PHP and XML
How to do it...
How it works...
Creating a simple REST client
How to do it...
Creating a streams-based REST client
Defining a cURL-based REST client
How it works...
There's more...
See also
Creating a simple REST server
How to do it...
How it works...
There's more...
Creating a simple SOAP client
How to do it...
How it works...
See also
Creating a simple SOAP server
How to do it...
How it works...
See also
8. Working with Date/Time and International Aspects
Introduction
Using emoticons or emoji in a view script
How to do it...
How it works...
See also
Converting complex characters
How to do it...
How it works...
Getting the locale from browser data
How to do it...
How it works...
See also
Formatting numbers by locale
How to do it...
How it works...
See also
Handling currency by locale
How to do it...
How it works...
See also
Formatting date/time by locale
How to do it...
How it works...
See also
Creating an HTML international calendar generator
How to do it...
Refining internationalized output
How it works...
See also
Building a recurring events generator
How to do it...
How it works...
See also
Handling translation without gettext
How to do it...
How it works...
See also
9. Developing Middleware
Introduction
Authenticating with middleware
How to do it...
How it works...
See also
Using middleware to implement access control
How to do it...
How it works...
See also
Improving performance using the cache
How to do it...
How it works...
There's more...
See also
Implementing routing
How to do it...
How it works...
See also
Making inter-framework system calls
How to do it...
How it works...
Using middleware to cross languages
How to do it...
10. Looking at Advanced Algorithms
Introduction
Using getters and setters
How to do it...
How it works...
Implementing a linked list
How to do it...
How it works...
There's more...
Building a bubble sort
How to do it...
How it works...
Implementing a stack
How to do it...
How it works...
Building a binary search class
How to do it...
How it works...
See also
Implementing a search engine
How to do it...
How it works...
Displaying a multi-dimensional array and accumulating totals
How to do it...
How it works...
11. Implementing Software Design Patterns
Introduction
Creating an array to object hydrator
How to do it...
How it works...
Building an object to array hydrator
How to do it...
How it works...
Implementing a strategy pattern
How to do it...
How it works...
Defining a mapper
How to do it...
How it works...
Implementing object-relational mapping
How to do it...
Technique #1 - pre-loading all child information
Technique #2 - embedding secondary lookups
How it works...
See also
Implementing the Pub/Sub design pattern
How to do it...
How it works...
There's more...
See also
12. Improving Web Security
Introduction
Filtering $_POST data
How to do it...
How it works...
See also
Validating $_POST data
How to do it...
How it works...
See also
Safeguarding the PHP session
How to do it...
How it works...
See also
Securing forms with a token
How to do it...
How it works...
See also
Building a secure password generator
How to do it...
How it works...
See also
Safeguarding forms with a CAPTCHA
How to do it...
Generating a text CAPTCHA
Generating an image CAPTCHA
How it works...
There's more...
See also
Encrypting/decrypting without mcrypt
How to do it...
How it works...
There's more...
See also
13. Best Practices, Testing, and Debugging
Introduction
Using Traits and Interfaces
How to do it...
How it works...
Universal exception handler
How to do it...
How it works...
See also
Universal error handler
How to do it...
How it works...
See also
Writing a simple test
How to do it...
Running simple tests
Testing database Model classes
Using mock classes
Using anonymous classes as mock objects
Using Mock Builder
How it works...
Running simple tests
Testing database model classes
Using mock classes
There's more...
See also...
Writing a test suite
How to do it...
How it works...
See also...
Generating fake test data
How to do it...
How it works...
There's more...
Customizing sessions using session_start parameters
How to do it...
How it works...
See also...
A. Defining PSR-7 Classes
Introduction
Implementing PSR-7 value object classes
Getting ready
How to do it...
How it works...
See also
Developing a PSR-7 Request class
How to do it...
How it works...
See also
Defining a PSR-7 Response class
How to do it...
How it works...
See also
2. Module 2
1. Setting Up the Environment
Setting up Windows
Setting up Debian or Ubuntu
Debian
Ubuntu
Setting up CentOS
Installing NGINX
Installing PHP 7
Installing Percona Server
Setting up Vagrant
Summary
2. New Features in PHP 7
OOP features
Type hints
Scalar type hints
Return type hints
Namespaces and group use declaration
Non mixed group use declarations
Mixed group use declarations
The compound namespace declaration
The anonymous classes
Old-style constructor deprecation
The throwable interface
Error
New operators
The Spaceship operator (<=>)
The null coalesce operator(??)
Uniform variable syntax
Miscellaneous features and changes
Constant arrays
Multiple default cases in the switch statement
The options array for session_start function
Filtered unserialize function
Summary
3. Improving PHP 7 Application Performance
NGINX and Apache
Apache
NGINX
HTTP server optimization
Caching static files
Apache
NGINX
HTTP persistent connection
Apache
NGINX
GZIP compression
Apache
NGINX
Using PHP as a separate service
Disabling unused modules
Apache
NGINX
Web server resources
NGINX
Content Delivery Network (CDN)
Using CDN
CSS and JavaScript optimization
Merging
Minifying
Minify
Grunt
Full page caching
Varnish
The infrastructure
Web servers
The database server
Load balancer (LB)
HAProxy load balancing
HAProxy installation
HAProxy load balancing
Summary
4. Improving Database Performance
The MySQL database
Query caching
Storage engines
The MyISAM storage engine
The InnoDB storage engine
innodb_buffer_pool_size
innodb_buffer_pool_instances
innodb_log_file_size
The Percona Server - a fork of MySQL
Installing the Percona Server
MySQL performance monitoring tools
phpMyAdmin
The MySQL workbench
Percona Toolkit
pt-query-digest
pt-duplicate-key-checker
Percona XtraDB Cluster (PXC)
Redis – the key-value cache store
Connecting with the Redis server
Storing and fetching data from the Redis server
Redis management tools
Memcached key-value cache store
Summary
5. Debugging and Profiling
Xdebug
Debugging with Sublime Text
Debugging with Eclipse
Profiling with Xdebug
PHP DebugBar
Summary
6. Stress/Load Testing PHP Applications
Apache JMeter
ApacheBench (ab)
Siege
Load testing real-world applications
Magento 2
WordPress 4
Drupal 8
Summary
7. Best Practices in PHP Programming
Coding styles
Test-driven development (TDD)
Design patterns
Service-oriented architecture (SOA)
Being object-oriented and reusable always
PHP frameworks
Version control system (VCS) and Git
Deployment and Continuous Integration (CI)
Summary
A. Tools to Make Life Easy
Composer – A dependency manager for PHP
Composer installation
Using Composer
Git – A version control system
Git installation
Using Git
Creating new branches and merging
Cloning a repository
Webhooks
Desktop tools to manage repositories
Grunt watch
Summary
B. MVC and Frameworks
The MVC design pattern
Model
Views
Controllers
Laravel
Installation
Features
Routing
Eloquent ORM
Artisan CLI
Migrations
Blade templates
Other features
Lumen
Apigility
Summary
3. Module 3
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
2. Prerequisites
Revision control
PHP version
Editor/IDE
Style Guide
Test suite
Review and next steps
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
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
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
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
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
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
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
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
Pick a View File name
Move Presentation Block to View file
Add Proper Escaping
Write View File Tests
The tests/views/ directory
Writing a View File Test
Asserting Correctness Of Content
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
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
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 QuestionsCan one class receive logic from many include files?
What about include calls originating in non-class files?
Review and next steps
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
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
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
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
Create a Container Service
Route the URL Path to the Container Service
Spot Check and Commit
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
17. Conclusion
Opportunities for improvement
Conversion to Framework
Review and next steps
A. Typical Legacy Page Script
B. Code before Gateways
C. Code after Gateways
D. Code after Transaction Scripts
E. Code before Collecting Presentation Logic
F. Code after Collecting Presentation Logic
G. Code after Response View File
H. Code after Controller Rearrangement
I. Code after Controller Extraction
J. Code after Controller Dependency Injection
Bibliography
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜