Book Image

Mastering Symfony

Book Image

Mastering Symfony

Overview of this book

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.
Table of Contents (17 chapters)
Mastering Symfony
Credits
About the Author
About the Reviewers
Index

Why Symfony?


I don't like to talk about features, numbers, and statistics. I don't do detailed comparisons between frameworks as well. Instead, I'd like to share an experience with you. As a PHP developer, I worked for the New Zealand Herald newspaper for a while. Sure, they are not the oldest newspaper in the world, but in 2013, they celebrated their 150th anniversary, which makes it very clear that over the years, they have created layers and layers of code on top of each other and used or tried almost every framework and technology in their website and internal newspaper systems. Their repositories contain tons of legacy codes written in different languages. You won't believe it if I say different parts of their system were implemented in Perl, Java, C#, ColdFusion, and PHP, and there was (perhaps, still is?) an API layer that acts as a communicating bridge between all of them.

Due to many factors such as maintenance costs, in the past few years, people at the NZ Herald decided to migrate their entire applications and services into one integrated system; something that is reliable, efficient, and easy to expand and maintain. Having experienced many frameworks already, the solution architects at NZ Herald chose Symfony as their framework.

They realized that those colorful graphs and pretty pictures that compare benchmarking results for various frameworks are worth nothing when it comes to real-life problems. They experienced the efficiency of various frameworks in the day-to-day challenges and understood that no matter how fast the development speed might look at the beginning, the most important thing is how reliable it actually is and how much it costs when it comes to maintaining the project. They simply put a price tag on many factors including performance, abstraction, decouplement, portability, integration, and above all, how well organized the code base will be after spending several years and using several men for the development. Guess what? Symfony beat every PHP framework out there.

What I'm trying to say is that Symfony is not just another tool for web app or website development. It is a new culture for web development, a solid reliable foundation that you can build your project on top of with peace of mind. I call it a new culture because for the first time, I see that it has made various PHP communities talk to each other and work together. I believe this is the most important PHP achievement ever. In the years to come, we will see more about this movement.

Influenced by Symfony

I believe one of the main reasons why Symfony stands out of the crowd is the way it defines the Model-View-Controller (MVC) design pattern. This is the key: Symfony defines MVC while many other frameworks try to simply follow MVC rules. Can you see the difference? This means that Symfony contains MVC but does not constrain it. Have a look at the MVC definition and keep it in mind that as we continue the journey through the chapters of this book, you will see what I mean by this. Maybe, this is reason that other PHP frameworks and Content Management Systems (CMS) adapted the Symfony components and started to follow in its footsteps.

If you look at the following link, you will see the other great players such as Drupal, phpBB, Laravel, Composer, Doctrine, Behat, and many others who use and benefit from Symfony components:

http://symfony.com/projects

For those who concern themselves with performance and their judgment is blinded by Hello World benchmarking results, I can talk about large companies such as BBC, CBS, and many others who chose Symfony.

Please don't tell me that these big boys didn't do due diligence before making a big decision like choosing a framework. They know the amount of pressure their website receives on a hourly basis and they do care about the quality of their service. There must be a good reason that they chose Symfony over other frameworks. In a nutshell, Symfony helps have a better organized code that reduces the maintenance costs tremendously and, at the same time, it can benefit from modern caching systems such as Varnish, which help with a better performance. Chapter 12, Caching in Symfony is all about performance improvement and caching systems.

How bright is the future?

In December 2013, when Fabien Potencier—the creator of Symfony—announced that he raised seven million dollars to boost Symfony and its ecosystem, I literally dropped other frameworks and decided to invest and focus even more on Symfony.

It is clear to me if he was capable of making his mark without raising money, then from 2014 onwards, he will be able to make a huge impact on the PHP world.

Don't get me wrong; I've been using other frameworks and respect other teams who made an effort to create a web development tool with PHP. I have used famous frameworks such as Zend to domestic packages such as MySource Matrix and SilverStripe. As a hobbyist, I also try new libraries and ideas in the open source world. However, every PHP developer needs to choose a right direction and set of tools as his main weapon. For me, it is Symfony, and I can see that Symfony developers will be in even higher demand soon.

Note

Assuming that you are an experienced PHP developer and familiar with open source development, the tutorials in this book are provided for Linux and Mac platforms. I politely invite Windows users to install a VM application such as Oracle VirtualBox and any Linux distribution to follow the provided examples. You can download it from https://www.virtualbox.org/.