logo资料库

PHP Objects Patterns and Practice(5th) 无水印pdf 0分.pdf

第1页 / 共583页
第2页 / 共583页
第3页 / 共583页
第4页 / 共583页
第5页 / 共583页
第6页 / 共583页
第7页 / 共583页
第8页 / 共583页
资料共583页,剩余部分请下载后查看
Cover
Copyright
Contents at a Glance
Contents
About the Author
Introduction
Part I: Objects
1: PHP: Design and Management
The Problem
PHP and Other Languages
About This Book
Objects
Patterns
Practice
What's New in the Fifth Edition
Summary
2: PHP and Objects
The Accidental Success of PHP Objects
In the Beginning: PHP/FI
Syntactic Sugar: PHP 3
PHP 4 and the Quiet Revolution
Change Embraced: PHP 5
PHP 7: Closing the Gap
Advocacy and Agnosticism: The Object Debate
Summary
3: Object Basics
Classes and Objects
A First Class
A First Object (or Two)
Setting Properties in a Class
Working with Methods
Creating a Constructor Method
Arguments and Types
Primitive Types
Primitive Types Matter: An Example
Taking the Hint: Object Types
Inheritance
The Inheritance Problem
Working with Inheritance
Constructors and Inheritance
Invoking an Overridden Method
Public, Private, and Protected: Managing Access to Your Classes
Accessor Methods
The ShopProduct Classes
Summary
4: Advanced Features
Static Methods and Properties
Constant Properties
Abstract Classes
Interfaces
Traits
A Problem for Traits to Solve
Defining and Using a Trait
Using More than One Trait
Combining Traits and Interfaces
Managing Method Name Conflicts with insteadof
Aliasing overridden trait methods
Using static methods in traits
Accessing Host Class Properties
Defining Abstract Methods in Traits
Changing Access Rights to Trait Methods
Late Static Bindings: The static Keyword
Handling Errors
Exceptions
Throwing an Exception
Subclassing Exception
Cleaning Up After try/catch Clauses with finally
Final Classes and Methods
The Internal Error Class
Working with Interceptors
Defining Destructor Methods
Copying Objects with __clone()
Defining String Values for Your Objects
Callbacks, Anonymous Functions, and Closures
Anonymous Classes
Summary
5: Object Tools
PHP and Packages
PHP Packages and Namespaces
Namespaces to the Rescue
Using the File System to Simulate Packages
Naming the PEAR Way
Include Paths
Autoload
The Class and Object Functions
Looking for Classes
Learning About an Object or Class
Getting a Fully Qualified String Reference to a Class
Learning About Methods
Learning About Properties
Learning About Inheritance
Method Invocation
The Reflection API
Getting Started
Time to Roll up Your Sleeves
Examining a Class
Examining Methods
Examining Method Arguments
Using the Reflection API
Summary
6: Objects and Design
Defining Code Design
Object-Oriented and Procedural Programming
Responsibility
Cohesion
Coupling
Orthogonality
Choosing Your Classes
Polymorphism
Encapsulation
Forget How to Do It
Four Signposts
Code Duplication
The Class Who Knew Too Much
The Jack of All Trades
Conditional Statements
The UML
Class Diagrams
Representing Classes
Attributes
Operations
Describing Inheritance and Implementation
Associations
Aggregation and Composition
Describing Use
Using Notes
Sequence Diagrams
Summary
Part II: Patterns
7: What Are Design Patterns? Why Use Them?
What Are Design Patterns?
A Design Pattern Overview
Name
The Problem
The Solution
Consequences
The Gang of Four Format
Why Use Design Patterns?
A Design Pattern Defines a Problem
A Design Pattern Defines a Solution
Design Patterns Are Language Independent
Patterns Define a Vocabulary
Patterns Are Tried and Tested
Patterns Are Designed for Collaboration
Design Patterns Promote Good Design
Design Patterns are Used By Popular Frameworks
PHP and Design Patterns
Summary
8: Some Pattern Principles
The Pattern Revelation
Composition and Inheritance
The Problem
Using Composition
Decoupling
The Problem
Loosening Your Coupling
Code to an Interface, Not to an Implementation
The Concept that Varies
Patternitis
The Patterns
Patterns for Generating Objects
Patterns for Organizing Objects and Classes
Task-Oriented Patterns
Enterprise Patterns
Database Patterns
Summary
9: Generating Objects
Problems and Solutions in Generating Objects
The Singleton Pattern
The Problem
Implementation
Consequences
Factory Method Pattern
The Problem
Implementation
Consequences
Abstract Factory Pattern
The Problem
Implementation
Consequences
Prototype
The Problem
Implementation
Pushing to the Edge: Service Locator
Splendid Isolation: Dependency Injection
The Problem
Implementation
Consequences
Summary
10: Patterns for Flexible Object Programming
Structuring Classes to Allow Flexible Objects
The Composite Pattern
The Problem
Implementation
Consequences
Composite in Summary
The Decorator Pattern
The Problem
Implementation
Consequences
The Facade Pattern
The Problem
Implementation
Consequences
Summary
11: Performing and Representing Tasks
The Interpreter Pattern
The Problem
Implementation
Interpreter Issues
The Strategy Pattern
The Problem
Implementation
The Observer Pattern
Implementation
The Visitor Pattern
The Problem
Implementation
Visitor Issues
The Command Pattern
The Problem
Implementation
The Null Object Pattern
The Problem
Implementation
Summary
12: Enterprise Patterns
Architecture Overview
The Patterns
Applications and Layers
Cheating Before We Start
Registry
The Problem
Implementation
Registry, Scope, and PHP
Consequences
The Presentation Layer
Front Controller
The Problem
Implementation
ApplicationHelper
CommandResolver
Request
A Command
Overview
Consequences
Application Controller
The Problem
Implementation
The Front Controller
Implementation Overview
The Configuration File
Parsing the Configuration File
Managing the Component Data
The Command Class
A Concrete Command
Consequences
Page Controller
The Problem
Implementation
Consequences
Template View and View Helper
The Problem
Implementation
Consequences
The Business Logic Layer
Transaction Script
The Problem
Implementation
Consequences
Domain Model
The Problem
Implementation
Consequences
Summary
13: Database Patterns
The Data Layer
Data Mapper
The Problem
Implementation
Handling Multiple Rows
Using a Generator in Place of the Iterator Interface
Acquiring Collection Objects
Consequences
Identity Map
The Problem
Implementation
Consequences
Unit of Work
The Problem
Implementation
Consequences
Lazy Load
The Problem
Implementation
Consequences
Domain Object Factory
The Problem
Implementation
Consequences
The Identity Object
The Problem
Implementation
Consequences
The Selection Factory and Update Factory Patterns
The Problem
Implementation
Consequences
What's Left of Data Mapper Now?
Summary
Part III: Practice
14: Good (and Bad) Practice
Beyond Code
Borrowing a Wheel
Playing Nice
Giving Your Code Wings
Standards
Vagrant
Testing
Continuous Integration
Summary
15: PHP Standards
Why Standards?
What Are PHP Standards Recommendations?
Why PSR in Particular?
Who Are PSRs for?
Coding with Style
PSR-1 Basic Coding Standard
Opening and Closing Tags
Side Effects
Naming
More Rules and an Example
PSR-2 Coding Style Guide
Starting and Ending a PHP Document
Starting and Ending a Class
Declaring Properties
Starting and Ending a Method
Single Line Declarations
Multi-line Declarations
Lines and Indentation
Calling Methods and Functions
Flow of Control
Checking and Fixing your Code
PSR-4 Autoloading
The Rules that Matter to Us
Summary
16: PHP Using and Creating Components with Composer
What Is Composer?
Installing Composer
Installing a (Set of) Package(s)
Installing a Package from the Command Line
Versions
require-dev
Composer and Autoload
Creating Your Own Package
Adding Package Information
Platform Packages
Distribution Through Packagist
Keeping it private
Summary
17: Version Control with Git
Why Use Version Control?
Getting Git
Using an Online Git Repository
Configuring a Git Server
Creating the Remote Repository
Preparing the Repository for Local Users
Providing Access to Users
Closing Down Shell Access for the git User
Beginning a Project
Cloning the Repository
Updating and Committing
Adding and Removing Files and Directories
Adding a File
Removing a File
Adding a Directory
Removing Directories
Tagging a Release
Branching a Project
Summary
18: Testing with PHPUnit
Functional Tests and Unit Tests
Testing by Hand
Introducing PHPUnit
Creating a Test Case
Assertion Methods
Testing Exceptions
Running Test Suites
Constraints
Mocks and Stubs
Tests Succeed When They Fail
Writing Web Tests
Refactoring a Web Application for Testing
Simple Web Testing
Introducing Selenium
Getting Selenium
PHPUnit and Selenium
Introducing php-webdriver
Creating the Test Skeleton
Connecting to Selenium
Writing the Test
A Note of Caution
Summary
19: Automated Build with Phing
What Is Phing?
Getting and Installing Phing
Composing the Build Document
Targets
Properties
Conditionally Setting Property Values with the Condition Task
Types
FileSet
PatternSet
FilterChain
Tasks
Echo
Copy
Input
Delete
Summary
20: Vagrant
The Problem
A Little Setup
Choosing and Installing a Vagrant Box
Mounting Local Directories on the Vagrant Box
Provisioning
Setting Up the Web Server
Setting Up MySQL
Configuring a Host Name
Wrapping It Up
Summary
21: Continuous Integration
What Is Continuous Integration?
Preparing a Project for CI
CI and Version Control
Phing
Unit Tests
Documentation
Code Coverage
Coding Standards
Installing Jenkins
Installing Jenkins Plug-ins
Setting up the Git Public Key
Installing a Project
Running the First Build
Configuring the Reports
Triggering Builds
Test Failures
Summary
22: Objects, Patterns, Practice
Objects
Choice
Encapsulation and Delegation
Decoupling
Reusability
Aesthetics
Patterns
What Patterns Buy Us
Tried and Tested
Patterns Suggest Other Patterns
A Common Vocabulary
Patterns Promote Design
Patterns and Principles of Design
Favor Composition over Inheritance
Avoid Tight Coupling
Code to an Interface, Not an Implementation
Encapsulate the Concept that Varies
Practice
Testing
Standards
Version Control
Automated Build
Continuous Integration
What I Missed
Summary
23: Appendix A: Bibliography
Books
Articles
Sites
24: Appendix B: A Simple Parser
The Scanner
The Parser
Index
分享到:
收藏