O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modular Programming with PHP 7

Book Description

Utilize the power of modular programming to improve code readability, maintainability, and testability

About This Book

  • This book demonstrates code reusability and distributed development to get high speed, maintainable, and fast applications

  • It illustrates the development of a complete modular application developed using PHP7 in detail

  • This book provides a high-level overview of the Symfony framework, a set of tools and a development methodology that are needed to build a modular web shop application

  • Who This Book Is For

    This step-by-step guide is divided into two sections. The first section explores all the fundamentals of modular design technique with respect to PHP 7. The latter section demonstrates the practical development of individual modules of a web shop application.

    What You Will Learn

  • Discover the new features of PHP 7 that are relevant to modular application development

  • Write manageable code based on the GoF design patterns and SOLID principles

  • Define the application requirements of a working modular application

  • Explore the ins and outs of the Symfony framework

  • Build a set of modules based on the Symfony framework that comprise a simple web shop app

  • Use core modules to set the structure and dependencies for other modules to use

  • Set up entities that are relevant to the module functionality and see how to manage these entities

  • In Detail

    Modular design techniques help you build readable, manageable, reusable, and more efficient codes. PHP 7, which is a popular open source scripting language, is used to build modular functions for your software. With this book, you will gain a deep insight into the modular programming paradigm and how to achieve modularity in your PHP code.

    We start with a brief introduction to the new features of PHP 7, some of which open a door to new concepts used in modular development. With design patterns being at the heart of all modular PHP code, you will learn about the GoF design patterns and how to apply them. You will see how to write code that is easy to maintain and extend over time with the help of the SOLID design principles.

    Throughout the rest of the book, you will build different working modules of a modern web shop application using the Symfony framework, which will give you a deep understanding of modular application development using PHP 7.

    Style and approach

    This book is for intermediate-level PHP developers with little to no knowledge of modular programming who want to understand design patterns and principles in order to better utilize the existing frameworks for modular application development.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Modular Programming with PHP 7
      1. Table of Contents
      2. Modular Programming with PHP 7
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. eBooks, discount offers, and more
          1. Why subscribe?
      7. 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
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Ecosystem Overview
        1. Getting ready for PHP 7
          1. Scalar type hints
          2. Return type hints
          3. Anonymous classes
          4. The Closure::call() method
          5. Generator delegation
          6. Generator return expressions
          7. The null coalesce operator
          8. The Spaceship operator
          9. Throwables
          10. The \ParseError
          11. Level support for the dirname() function
          12. The integer division function
          13. Constant arrays
          14. Uniform variable syntax
          15. Secure random number generator
          16. Filtered unserialize()
          17. Context sensitive lexer
          18. Group use declarations
          19. Unicode enhancements
          20. Assertions
          21. Changes to the list() construct
          22. Session options
          23. Deprecated features
          24. Frameworks
            1. Laravel framework
            2. Symfony
            3. Zend Framework
            4. CodeIgniter
            5. CakePHP
            6. Slim
            7. Yii
            8. Phalcon
        2. Summary
      9. 2. GoF Design Patterns
        1. Creational patterns
          1. Abstract factory pattern
          2. Builder pattern
          3. Factory method pattern
          4. Prototype pattern
          5. Singleton pattern
        2. Structural patterns
          1. Adapter pattern
          2. Bridge pattern
          3. Composite pattern
          4. Decorator pattern
          5. Facade pattern
          6. Flyweight pattern
          7. Proxy pattern
        3. Behavioral patterns
          1. Chain of responsibility pattern
          2. Command pattern
          3. Interpreter pattern
          4. Iterator pattern
          5. Mediator pattern
          6. Memento pattern
          7. Observer pattern
          8. State pattern
          9. Strategy pattern
          10. Template pattern
          11. Visitor pattern
        4. Summary
      10. 3. SOLID Design Principles
        1. Single responsibility principle
        2. Open/closed principle
        3. Liskov substitution principle
        4. Interface Segregation Principle
        5. Dependency inversion principle
        6. Summary
      11. 4. Requirement Specification for a Modular Web Shop App
        1. Defining application requirements
        2. Wireframing
        3. Defining a technology stack
          1. The Symfony framework
          2. Foundation framework
        4. Summary
      12. 5. Symfony at a Glance
        1. Installing Symfony
        2. Creating a blank project
        3. Using Symfony console
        4. Controller
        5. Routing
        6. Templates
        7. Forms
        8. Configuring Symfony
        9. The bundle system
        10. Databases and Doctrine
        11. Testing
        12. Validation
        13. Summary
      13. 6. Building the Core Module
        1. Requirements
        2. Dependencies
        3. Implementation
          1. Configuring application-wide security
        4. Unit testing
        5. Functional testing
        6. Summary
      14. 7. Building the Catalog Module
        1. Requirements
        2. Dependencies
        3. Implementation
          1. Creating entities
          2. Managing image uploads
          3. Overriding core module services
          4. Setting up a Category page
          5. Setting up a Product page
        4. Unit testing
        5. Functional testing
        6. Summary
      15. 8. Building the Customer Module
        1. Requirements
        2. Dependencies
        3. Implementation
          1. Creating a customer entity
          2. Modifying the security configuration
          3. Extending the customer entity
          4. Creating the orders service
          5. Creating the customer menu service
          6. Implementing the register process
          7. Implementing the login process
          8. Implementing the logout process
          9. Managing forgotten passwords
        4. Unit testing
        5. Functional testing
        6. Summary
      16. 9. Building the Payment Module
        1. Requirements
        2. Dependencies
        3. Implementation
          1. Creating a card entity
            1. Creating a card payment service
          2. Creating a card payment controller and routes
          3. Creating a check money payment service
          4. Creating a check money payment controller and routes
        4. Unit testing
        5. Functional testing
        6. Summary
      17. 10. Building the Shipment Module
        1. Requirements
        2. Dependencies
        3. Implementation
          1. Creating a flat rate shipment service
          2. Creating a flat rate shipment controller and routes
          3. Creating a dynamic rate payment service
          4. Creating a dynamic rate shipment controller and routes
        4. Unit testing
        5. Functional testing
        6. Summary
      18. 11. Building the Sales Module
        1. Requirements
        2. Dependencies
        3. Implementation
          1. Creating a Cart entity
          2. Creating the cart item entity
          3. Creating an Order entity
          4. Creating a SalesOrderItem entity
          5. Overriding the add_to_cart_url service
          6. Overriding the checkout_menu service
          7. Overriding the customer orders service
          8. Overriding the bestsellers service
          9. Creating the Cart page
          10. Creating the Payment service
          11. Creating the Shipment service
          12. Creating the Checkout page
          13. Creating the order success page
          14. Creating a store manager dashboard
        4. Unit testing
        5. Functional testing
        6. Summary
      19. 12. Integrating and Distributing Modules
        1. Understanding Git
        2. Understanding GitHub
        3. Understanding Composer
        4. Understanding Packagist
        5. Summary
      20. Index