Mastering Symfony

Book description

Orchestrate the designing, development, testing, and deployment of web applications with Symfony

About This Book

  • Create a robust and reliable Symfony development pipeline using Amazon's cloud platform
  • Cut development and maintenance costs by defining crystal clear features and possible scenarios for each feature before implementation
  • Follow detailed examples provided in each chapter to create a task management application

Who This Book Is For

If you are a PHP developer with some experience in Symfony and are looking to master the framework and use it to its full potential, then this book is for you. Though experience with PHP, object-oriented techniques, and Symfony basics is assumed, this book will give you a crash course on the basics and then proceed to more advanced topics.

What You Will Learn

  • Install and configure Symfony and required third-party bundles to develop a task management application
  • Set up a continuous integration server to orchestrate automatic builds every time you add a new feature to your project
  • Reduce maintenance costs dramatically using Behaviour Driven Development (BDD)
  • Create a slick user interface using the Bootstrap framework
  • Design robust business logic using Doctrine
  • Build a comprehensive dashboard and secure your project using the Sonata project
  • Improve performance using Redis, Memcache, and Varnish
  • Create customized Symfony commands and add them to your console

In Detail

In this book, you will learn some lesser known aspects of development with Symfony, and you will see how to use Symfony as a framework to create reliable and effective applications. You might have developed some impressive PHP libraries in other projects, but what is the point when your library is tied to one particular project? With Symfony, you can turn your code into a service and reuse it in other projects.

This book starts with Symfony concepts such as bundles, routing, twig, doctrine, and more, taking you through the request/response life cycle. You will then proceed to set up development, test, and deployment environments in AWS. Then you will create reliable projects using Behat and Mink, and design business logic, cover authentication, and authorization steps in a security checking process. You will be walked through concepts such as DependencyInjection, service containers, and services, and go through steps to create customized commands for Symfony's console. Finally, the book covers performance optimization and the use of Varnish and Memcached in our project, and you are treated with the creation of database agnostic bundles and best practices.

Style and approach

A step-by-step guide to mastering Symfony while developing a task management application. Each chapter comes with detailed examples.

Publisher resources

Download Example Code

Table of contents

  1. Mastering Symfony
    1. Table of Contents
    2. Mastering Symfony
    3. Credits
    4. About the Author
    5. About the Reviewers
      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. Installing and Configuring Symfony
      1. Why Symfony?
        1. Influenced by Symfony
        2. How bright is the future?
      2. Installation
      3. Composer and Packagist
        1. Installing Symfony via Composer
        2. The road map
        3. Checking the installation
      4. Summary
    9. 2. The Request and Response Life Cycle
      1. The big picture
      2. Anatomy of a bundle
        1. Generating a new bundle
        2. Best practices
      3. Custom bundles versus AppBundle
      4. Creating templates with TWIG
        1. Controller/View interaction
        2. Conditional templates
        3. Make it dynamic
        4. Database configurations
        5. Generating an entity
        6. Installing bundles created by others
      5. Creating data fixtures
        1. Loading data fixtures
      6. Dynamic templates and controllers
      7. The big picture with MVC
      8. Summary
    10. 3. Setting Up the Environment
      1. The importance of Continuous Integration
      2. Amazon Web Services
      3. Elastic Compute Cloud
        1. Creating a new instance
      4. Setting up the server
        1. Installing Apache
        2. Installing MySQL and PHP
        3. Installing Jenkins
        4. Setting up security and installing plugins in Jenkins
      5. Simple Email Service
        1. Configuring Jenkins
      6. Installing PHP tools
        1. Sniff Symfony codes
      7. Orchestrating the build process
      8. Creating a new job in Jenkins
      9. Running the first build
        1. How does GitHub alert Jenkins about new pushes?
      10. Do I need CI?
      11. Summary
    11. 4. Using Behavior-Driven Development in Symfony
      1. Getting started with BDD
        1. Is BDD a replacement for TDD?
      2. What is Behat?
        1. Installing and configuring Behat
        2. The features we need for this project
          1. More information about the project
        3. Gherkin – the common language
      3. Writing a scenario for the about page
        1. Seeing it in action
        2. Headless versus zombie
        3. Using the Selenium2 controller for automated tests
      4. The about page does not follow BDD
        1. A scenario to show the user's details
        2. Implementing the user's details scenario
        3. Testing the scenario
      5. More about the acceptance test flow in Mink
      6. Defining and prioritizing features
      7. Codeception – the BDD style testing framework
        1. Installing the Codeception framework
        2. Bootstrapping Codeception
        3. Test suits
        4. The testers
        5. Adding sample tests
        6. Running the tests
      8. Summary
    12. 5. Business Logic
      1. Choosing between creating a Model or entity
      2. So where does the business logic live?
      3. Reviewing the facts and building entity relationships
        1. Creating ERDs using MySQL Workbench
        2. Adding a new entity
        3. Adding a new relationship
        4. Creating actual tables from a diagram
        5. Generating entities
        6. Data fixtures
      4. Some business logic features and scenarios
      5. TDD and BDD with Codeception
        1. Step one – creating a functional test
        2. Developing the missing code
        3. Step two – creating the unit tests
        4. Setting up the database for a test environment in the right way
        5. Dropping and recreating the database for each test
        6. Creating unit tests
        7. Writing the code to pass the test
        8. Running functional and unit tests
        9. Step three – creating an acceptance test
      6. On the CI side of the story
      7. Summary
    13. 6. Dashboard and Security
      1. How security is organized in Symfony?
        1. Authentication
        2. Authorization
      2. Handling users with FOSUserBundle
        1. Security settings
        2. Adding the required configurations to FOSUserBundle
        3. Adding routes
        4. Updating the tables
        5. A simple road test
      3. Generating automated data fixtures
        1. Introducing AliceBundle
        2. Creating data fixtures with Alice
        3. Relationship with Alice
        4. Setting up the login redirection
          1. Creating tests for the new controller
          2. Creating the Dashboard Controller
          3. Securing the dashboard
      4. The Sonata project
        1. Installing and configuring Sonata bundle
        2. Adding contents to the dashboard
        3. Creating admin feature for entities with relations
      5. Integrating FOSUserBundle into the admin area
        1. Installing SonataUserBundle
        2. SonataUserBundle configuration
        3. Updating the routes
        4. Setting the security
        5. Checking the installation
        6. Putting SonataUserBundle in charge
      6. User dashboard
      7. Generating CRUD
        1. Modifying the forms
      8. Summary
    14. 7. The Presentation Layer
      1. How assets are organized
      2. Asset management
      3. How templates are organized
      4. Let's mold the clay
      5. To navigate or not to navigate
      6. What is Bootstrap?
      7. MopaBootstrapBundle
        1. Bootstrap configuration
      8. Creating your first menu
        1. Rendering the menu in a template
      9. The Dashboard template
      10. Overriding templates
        1. Profile-related templates
      11. Changing the backend logo
      12. Summary
    15. 8. Project Review
      1. The dashboard's contents
        1. Visual blocks that provide statistics about tasks
        2. A feature file for the finished tasks block
        3. Implementing the finished tasks block
        4. Implementing the dashboard controller
      2. Uploading files with SonataMediaBundle
        1. Adding an attachment feature to the Task entity
      3. Team and team members
        1. The Team entity
      4. Adding a notification system
        1. Adding time tracking properties
      5. The notification business logic
        1. Events, event dispatchers, and event listeners
        2. The Notifier event listener
      6. Summary
    16. 9. Services and Service Containers
      1. How to create a service
      2. How are services beneficial to our projects?
      3. How to call a service
      4. How to configure a service
      5. Why is it called a Dependency Injection Container?
      6. Why didn't we import services inside the bundle?
      7. How to create and load services via autowiring
      8. Organizing services with tags
      9. Summary
    17. 10. Custom User Commands
      1. Creating and registering commands
      2. Creating commands for tasks
        1. The configuration part
        2. The execution part
      3. Adding interactivity to commands
        1. Console helpers
      4. Summary
    18. 11. More about Dev, Test and Prod Environments
      1. Why do we need different environments?
        1. The environment configuration file
      2. Processing configuration files
      3. Creating a new environment
        1. The config file
        2. The front controller
      4. Summary
    19. 12. Caching in Symfony
      1. Definition of a cache
        1. Characteristics of a good cache
      2. Caches in a Symfony project
      3. Key players in the HTTP cache header
      4. Using the Symfony reverse proxy cache
        1. Set expiration for dashboard page
        2. Validation strategy
      5. How to mix expiration and validation strategies
        1. Doctrine cache
      6. Putting it all together
      7. ESI for selective caching
      8. Sophisticated bundles
      9. Summary
    20. Index

Product information

  • Title: Mastering Symfony
  • Author(s): Sohail Salehi
  • Release date: April 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781784390310