You are previewing Expert PHP 5 Tools.
O'Reilly logo
Expert PHP 5 Tools

Book Description

Proven enterprise development tools and best practices for designing, coding, testing, and deploying PHP applications

  • Best practices for designing, coding, testing, and deploying PHP applications – all the information in one book

  • Learn to write unit tests and practice test-driven development from an expert

  • Set up a professional development environment with integrated debugging capabilities

  • Develop your own coding standard and enforce it automatically

  • Document your code for easy maintainability for yourself and others

  • In Detail

    Even if you find writing PHP code easy, writing code that is efficient and easy to maintain and reuse is not so straightforward. Self-taught PHP developers and programmers transitioning from other languages often lack the knowledge to work with PHP on an enterprise level. They need to take their PHP development skills to that level by learning the skills and tools necessary to write maintainable and efficient code.

    This book will enable you to take your PHP development skills to an enterprise level by teaching you the skills and tools necessary to write maintainable and efficient code. You will learn how to perform activities such as unit testing, enforcing coding standards, automating deployment, and interactive debugging using tools created for PHP developers – all the information in one place. Your code will be more maintainable, efficient, and self-documented.From the design phase to actually deploying the application, you will learn concepts and apply them using the best-of-breed tools available in PHP.

    Experienced developers looking for expertise in PHP development will learn how to follow best practices within the world of PHP. The book contains many well-documented code samples and recipes that can be used as a starting point for producing quality code.

    Specifically, you will learn to design an application with UML, code it in Eclipse with PDT, document it with phpDocumentor, debug it interactively with Xdebug, test it by writing PHPUnit tests, manage source code in Subversion, speed up development and increase stability by using Zend Framework, pull everything together using continuous integration, and deploy the application automatically with Phing – all in one book. The author's experience in PHP development enables him to share insights on using enterprise tools, in a clear and friendly way.

    An in-depth look at best-of-breed enterprise-level tools, methodologies, and tips for professional PHP developers to write maintainable, efficient code

    Table of Contents

    1. Expert PHP 5 Tools
      1. Expert PHP 5 Tools
      2. Credits
      3. About the Author
      4. About the Reviewers
      5. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code for the book
          2. Errata
          3. Piracy
          4. Questions
      6. 1. Coding Style and Standards
        1. Coding standard considerations
          1. Pros
          2. Cons
        2. A PHP coding standard
          1. Formatting
            1. PHP tags
            2. Indenting
            3. Line length
            4. Line endings
            5. Spacing
            6. Statements
            7. Strings
            8. Arrays
            9. Control structures
              1. If-elseif-else statements
              2. Switch statements
            10. Class and method definitions
          2. Naming conventions
            1. Class names
            2. Property and variable names
            3. Constant names
            4. Method and function names
          3. Methodology
            1. Type hinting
            2. Separating object creation from initialization
            3. Class files
            4. Class names and directory structures
            5. Visibility and access
            6. Including source files
            7. Comments
            8. Inline documentation
        3. Coding standard adherence and verification
          1. PHP_CodeSniffer for automated checking
            1. Installing PHP_CodeSniffer
            2. Basic usage
            3. Slightly advanced usage
            4. Validating against your own coding standard
              1. Creating the directories
              2. The main coding standard class file
              3. Creating Sniffs
                1. Tokenization
                2. Writing our first sniff
                3. Extending existing sniffs
                4. Automated code checks
        4. Summary
      7. 2. Documentation with phpDocumentor
        1. Code-level documentation
          1. Levels of detail
        2. Introducing phpDocumentor
          1. Installing phpDocumentor
          2. DocBlocks
            1. Short and long descriptions
            2. Tags
          3. DocBlock templates
          4. Tutorials
            1. Naming conventions and how to reference tutorials
            2. DocBook syntax
          5. Documenting a project
            1. Documentation without DocBlocks
            2. Documentation with DocBlocks
          6. phpDocumentor options
            1. Command line reference
            2. Config files
            3. Browser-based interface
          7. Tag reference
            1. Standard tags
              1. @access
              2. @author
              3. @category
              4. @copyright
              5. @deprecated
              6. @example
              7. @filesource
              8. @global
              9. @ignore
              10. @internal
              11. @license
              12. @link
              13. @method
              14. @name
              15. @package
              16. @property
              17. @return
              18. @see
              19. @since
              20. @static
              21. @staticvar
              22. @subpackage
              23. @todo
              24. @tutorial
              25. @uses
              26. @var
              27. @version
            2. Inline tags
              1. {@Example}
              2. {@id}
              3. {@internal}}
              4. {@inheritdoc}
              5. {@link}
              6. {@source}
              7. {@toc}
              8. {@tutorial}
          8. PHP4 elements
          9. Custom tags
        3. Summary
      8. 3. The Eclipse Integrated Development Environment
        1. Why Eclipse?
        2. Introducing PDT
        3. Installing Eclipse
          1. Requirements
          2. Choosing a package
          3. Adding the PDT plugin
        4. Basic Eclipse concepts
          1. Workspace
          2. Views
          3. Perspectives
        5. A PDT sample project
        6. PDT features
          1. Editor
            1. Syntax highlighting
            2. Code assist
            3. Code folding
            4. Mark occurrences
            5. Override indicators
            6. Type, method, and resource navigation
          2. Inspection
            1. Projects and files
            2. PHP explorer
            3. Type hierarchy
          3. Debugging
          4. PDT preferences
            1. Appearance
            2. Code style
              1. Formatter
              2. Code templates
            3. Debug
              1. Installed debuggers
              2. Step filtering
              3. Workbench options
            4. Editor
              1. Code assist
              2. Code folding
              3. Hovers
              4. Mark occurrences
              5. Save actions
              6. Syntax coloring
              7. Task tags
              8. Typing
            5. New project layout
            6. PHP executables
            7. PHP interpreter
            8. PHP manual
            9. PHP servers
            10. Templates
          5. Other features
            1. PHP function reference
          6. Eclipse plugins
        7. Zend Studio for Eclipse
          1. Support
          2. Refactoring
          3. Code generation
          4. PHPUnit testing
          5. PhpDocumentor support
          6. Zend Framework integration
          7. Zend server integration
        8. Summary
      9. 4. Source Code and Version Control
        1. Common use cases
        2. A brief history of source code control
        3. CVS
        4. Introducing Subversion
          1. Client installation
          2. Server configuration
            1. Apache with mod_dav_svn
              1. svnserve
          3. Subversion concepts
            1. Repository
            2. Tags
            3. Trunk
            4. Branches
            5. Working (Local) copy
            6. Merging
            7. Revisions and versions
            8. Updating
            9. Comparing
            10. History/Log
            11. Annotating code
            12. Reverting
            13. Committing
          4. Subversion command reference
            1. svn
              1. blame
              2. cat
              3. changelist
              4. checkout
              5. cleanup
              6. commit
              7. copy
              8. delete
              9. diff
              10. export
              11. help
              12. import
              13. info
              14. list
              15. lock
              16. log
              17. merge
              18. mergeinfo
              19. mkdir
              20. move
              21. propdel
              22. propedit
              23. propget
              24. proplist
              25. propset
              26. resolve
              27. resolved
              28. revert
              29. status
              30. switch
              31. unlock
              32. update
            2. svnadmin
              1. create
              2. dump
            3. svnlook
            4. svnserve
            5. svndumpfilter
            6. svnversion
          5. Creating a Subversion project
          6. Basic version control workflow
          7. A closer look at the repository
            1. Data store
            2. Layout
          8. Branching and merging
            1. What is a branch?
            2. Why branch?
            3. How to branch?
            4. Maintaining and merging a branch
            5. Branching workflow
          9. UI clients
            1. Eclipse plug-ins
            2. TortoiseSVN
            3. WebSVN
        5. Subversion conventions and best practices
          1. Customizing Subversion
            1. Hooks
              1. Enforcing coding standards with a pre-commit hook
            2. Notifying developers of commits with a post-commit hook
        6. Summary
      10. 5. Debugging
        1. First line of defense: syntax check
        2. Logging
          1. Configuration options
          2. Customizing and controlling config options: PhpIni
            1. PhpIni example
        3. Outputting debug information
          1. Functions
            1. echo(string $arg1 [, string $... ] / print(string $arg)
            2. var_dump(mixed $expression [, mixed $expression [, $... ]]) and print_r(mixed $expression [, bool $return= false ])
            3. highlight_string(string str [, bool return]) and highlight_file(string filename [, bool return])
            4. get_class([object object])
            5. get_object_vars(object object)
            6. get_class_methods(mixed class_name)
            7. get_class_vars(string class_name)
            8. debug_backtrace()
            9. debug_print_backtrace()
            10. exit([string status]) or exit (int status)
          2. Magic constants
          3. Writing our own debugging class
            1. Functional requirements
            2. DebugException
              1. Using DebugException
              2. DebugException: Pros and cons
        4. Introducing Xdebug
          1. Installing Xdebug
          2. Configuring Xdebug
          3. Immediate benefits
            1. var_dump() improved
            2. var_dump() settings
            3. Errors and exceptions beautified
              1. Stack trace settings
            4. Protection from infinite recursion
          4. Remote debugging
            1. Remote server debug configuration
            2. Debugging client configuration
        5. Summary
      11. 6. PHP Frameworks
        1. Writing your own framework
        2. Evaluating and choosing frameworks
          1. Community and acceptance
          2. Feature road map
          3. Documentation
          4. Code quality
          5. Coding standards and compliance
          6. Project fit
          7. Easy to learn and adapt
          8. Open source
          9. Familiarity
          10. Their rules
        3. Popular PHP frameworks
          1. Zend
          2. CodeIgniter
          3. Symfony
          4. Yii
        4. Zend Framework application
          1. Feature list
          2. Application skeleton
            1. Important concepts
              1. Bootstrapping
              2. MVC
            2. Application structure detail
              1. Model: application/models/
              2. View: application/views/
              3. Controller: application/controllers/
              4. Configuration: application/configs/
              5. Library
              6. Public
              7. Tests
          3. Enhancements
            1. Adding a layout
            2. Adding views
            3. Adding logging
            4. Adding a database
            5. Adding a model
            6. Adding a controller
            7. Putting it all together
        5. Summary
      12. 7. Testing
        1. Testing methods
          1. Black box
          2. White box
          3. Gray box
        2. Types of testing
          1. Unit testing
          2. Integration testing
          3. Regression testing
          4. System testing
          5. User acceptance testing
        3. Introducing PHPUnit
          1. Installing PHPUnit
          2. String search project
            1. BMH algorithm basics
            2. Implementing BMH
            3. Unit testing BoyerMooreStringSearch
            4. The test class
            5. Assertions
            6. Organization
            7. Our first unit test
            8. Extended test class features
              1. Fixtures
              2. Annotations
                1. Data providers
                2. Exceptions
            9. Automation: generating tests from classes
              1. Unimplemented and skipped tests
            10. Automation: generating classes from tests
            11. Test-driven development
              1. Enhancing our example with TDD
          3. Code coverage
          4. TestCase subclasses
        4. Summary
      13. 8. Deploying Applications
        1. Goals and requirements
        2. Deploying your application
          1. Checking out and uploading files
          2. Displaying an under-maintenance message
          3. Upgrading and installing files
          4. Upgrading database schema and data
          5. Rotating log files and updating symbolic links
          6. Verifying the deployed application
        3. Automating deployment
          1. Phing
            1. Installing Phing
          2. Basic syntax and file structure
            1. Tasks
            2. Targets
            3. Properties and property files
          3. Types
            1. Filters
            2. Mappers
            3. The project tag
          4. Deploying a site
            1. Separating external dependencies
            2. Creating a build script
              1. Environment and properties
            3. Directory skeleton
            4. Subversion export and checkout
            5. Building files from templates
            6. Maintenance page
            7. Database backup
            8. Database migrations
            9. Going live
            10. Putting it all together
            11. Backing out
        4. Summary
      14. 9. PHP Application Design with UML
        1. Meta-model versus notation versus our approach
        2. Levels of detail and purpose
        3. Round-trip and one-way tools
        4. Basic types of UML diagrams
        5. Diagrams
          1. Class diagrams
            1. Elements of a class
              1. Properties (Attributes)
              2. Methods (Operations)
            2. Static methods and properties
            3. A class diagram example
            4. Relationships
              1. Association
              2. Aggregation
              3. Composition
              4. Dependency
              5. Generalization
            5. Interfaces
            6. Example refactored
            7. Code generators
          2. Sequence diagrams
            1. Scope
            2. A sequence diagram of the network scanner
              1. Objects and lifelines
              2. Methods
              3. Creating and destroying object
              4. Loops and conditionals
              5. Synchronous versus asynchronous calls
          3. Use cases
            1. Use cases — diagrams optional
            2. When to create use cases
            3. Example use case
              1. Background
              2. Typical scenario
              3. Example use case diagram
              4. Actors
              5. System boundary
              6. Use cases
              7. Relationships
        6. Summary
      15. 10. Continuous Integration
        1. The satellite systems
          1. Version control: Subversion
            1. Commit frequency
          2. Testing: PHPUnit
          3. Automation: Phing
          4. Coding style: PHP_CodeSniffer
          5. Documentation: PhpDocumentor
          6. Code coverage: Xdebug
        2. Environment setup considerations
          1. Do I need a dedicated CI server?
          2. Do I need a CI tool?
        3. CI tools
          1. XINC (Xinc Is Not CruiseControl)
          2. phpUnderControl
        4. Continuous integration with phpUnderControl
          1. Installation
            1. Installing CruiseControl
            2. Installing phpUnderControl
            3. Overlaying CruiseControl with phpUnderControl
          2. CruiseControl configuration
          3. Overview of the CI process and components
            1. CruiseControl and project layout
            2. Getting the project source
            3. Configuring the project: build.xml
            4. Configuring CruiseControl
            5. Advanced options
              1. Bootstrappers
              2. Publishers
            6. Running CruiseControl
              1. The overview page
              2. The tests page
              3. Metrics
              4. Coverage
              5. Documentation
              6. CodeSniffer
              7. PHPUnit PMD
            7. Replacing Ant with Phing
        5. Summary