You are previewing Extending Symfony2 Web Application Framework.
O'Reilly logo
Extending Symfony2 Web Application Framework

Book Description

Symfony2 took the great features of the original framework to new levels of extensibility. With this practical guide you’ll learn how to make the most of Symfony2 through controlling your code and sharing it more widely.

In Detail

Symfony is a high performance PHP framework for developing MVC web applications. Symfony1 allowed for ease of use but its shortcoming was the difficulty of extending it. However, this difficulty has now been eradicated by the more powerful and extensible Symfony2. Information on more advanced techniques for extending Symfony can be difficult to find, so you need one resource that contains the advanced features in a way you can understand.

This tutorial offers solutions to all your Symfony extension problems. You will get to grips with all the extension points that Symfony, Twig, and Doctrine offer and understand how each of them can be specifically leveraged to achieve cleaner, better structured, and re-usable code for your application.

Beginning with the core concepts of Services and Listeners, you quickly move on to learn the complexity of forms, creating commands, and implementing security, and finally you will share these extensions with others. This book will tell you everything you need to know to regain control of your code, to keep things simple, and share it within your application(s) or even the world. Whether you have already written extensions for Symfony2 or not, this book will be a useful guide through all possible types of extensions, and how each of them can be implemented and leveraged in your own applications.

What You Will Learn

  • Make and review services and listeners
  • Integrate your extension with specific hooks
  • Create custom commands, templates, and database integration
  • Customize the security layer
  • Configure extensions to share with the community
  • Integrate to the same level as Symfony's core modules
  • 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 If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Extending Symfony2 Web Application Framework
      1. Table of Contents
      2. Extending Symfony2 Web Application Framework
      3. Credits
      4. About the Author
      5. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      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. Errata
          3. Piracy
          4. Questions
      8. 1. Services and Listeners
        1. Services
          1. A geolocation service
          2. Testing services and testing with services
          3. Tagging services
        2. Listeners
          1. Updating user preferences using custom events
          2. Improving user performance
            1. Code that works after the response
        3. Summary
      9. 2. Commands and Templates
        1. Commands
          1. The initial situation
          2. Resizing user pictures
          3. Testing a command
          4. Commands as an interface to services
        2. Twig
          1. Managing our scripts
          2. Testing a Twig extension
          3. The time difference filter
        3. Summary
      10. 3. Forms
        1. An input for geographical coordinates
          1. Setting up the basics
          2. Using the map
        2. Data transformers
        3. Forms based on user data
        4. Going further
          1. The initial setup
          2. Adding and removing fields
        5. Summary
      11. 4. Security
        1. Authentication
          1. Simple OAuth with GitHub
            1. The firewall
            2. The security factory
        2. Authorization
          1. Voters
          2. Annotations
            1. Defining an annotation
            2. Securing controllers with custom annotations
        3. Securing an API – an example
        4. Summary
      12. 5. Doctrine
        1. Creating your own data types
          1. User and meetup locations
          2. Testing
        2. Custom DQL functions
        3. Versioning
          1. Setting a version on all entities
          2. Using and updating versions
          3. Testing
        4. Creating a Doctrine filter
        5. Summary
      13. 6. Sharing Your Extensions
        1. Creating the bundle
          1. Exposing the configuration
        2. Getting ready to share
          1. Research
          2. Documentation
          3. Testing
          4. Distribution and licensing
          5. Is it just a bundle?
        3. Summary
      14. Index