June 30, 2016 Technologies
I recommend Symfony2
Two weeks ago, we shared an article from one of our developers that made a case for the Laravel framework, winning our internal contest with entry tickets to the Laracon conference as the main prize. This time, we are equally proud to share another winning article, centered around the Symfony2 framework. It won another one of our developers, Marek, an entry to this year’s Symfony Con.
A brief introduction to Symfony
Generally speaking, a framework is a collection of libraries that facilitate the development of repetitive functionalities in applications. Such functionalities may include error handling, connection to the database or sending emails. Frameworks make development faster and more effective.
It was Symfony2, however, that proved to be revolutionary. The very same programmers that sharpened their skills developing Symfony1, managed to create a framework that entirely outclassed its competition with its design patterns, innovative approach to data flow management mechanisms in an application and more. Rich documentation and a streamlined way of adding new functionalities and modules by the core Symfony2 team made the project even more universal.
This comprehensive documentation is a go-to place for every adept of the Symfony framework
How to convince programmers to use Symfony2?
Each and every programmer appreciates coherent and universal code. Symfony2 allows one to write apps in a clear manner, making use of the best programming techniques. Those straightforward and clear standards the framework uses make it possible for the programmer to get familiar with a project rapidly. Its comprehensive documentation and growing community of programmers ensure easy access to any class, method or functionality you want to use in your project. The introduction of new modules (bundles) as well as the improvement of existing ones make Symfony2 a project with enormous room for development.
Most of PHP frameworks aim to create a programming environment that simplifies the development of web applications. Depending on their intended use (blog, portal or CRM), their structure and the way it works may vary greatly. A programmer that uses WordPress to develop a blog receives access to ready-made “puzzles” with which to make the final product. It makes development fast and easy, but at the same time limits the ability to customize the project. The more a framework focuses on a specific type of an app, the more difficult it is to adapt it to another one. It’s true for every framework out there. A programmer that wants to grow and be able to handle all kinds of projects needs a framework that provides a good compromise between ease of use and versatility. Symfony2 does just that. You can easily overwrite each module with your own code. As a result, each functionality of the framework can be easily extended to no end.
Another important factor for each PHP programmer is how their framework works together with other technologies. Thanks to ready-made modules and good support, Symfony2 users get well-tested components for use in their apps. These may include:
- ready-to-use APIs of various web services, such as Yahoo, Facebook or Google;
- user support and authorization mechanism such as FOSUserBundle;
- the angular-symfony module that allows you to integrate AngularJS;
- the WebSocketBundle bundle;
- a lot of other components that facilitate integration.
Symfony2’s structure, architecture and the nature of its mechanisms make it extremely versatile. It can be easily used to write a blog as well as a large application. Most of the modules are well-tested. The composer tool ensures safe management of dependencies and versions of each component. It virtually rules out the possibility of version incompatibilities. It’s also worth adding that the framework is equipped with a profiler that can be viewed in the developer mode. It shows all parameters and variables present in the Symfony2 environment. It includes elements such as HTTP queries, HTTP responses, security provisions and permissions, translations, configurations, logs, initiated events, forms and related data, routing, the Twig template system along with its parameters, database query, response and rendering execution time.
The growing popularity of Symfony2 and increasing amount of projects that use the framework provide many job opportunities for Symfony specialists.
Another factor that makes Symfony2 worth a try are the technological choices made by its creators:
- MVC architecture (model-view-controller).
- Integration with Doctrine 2 – one of the most popular ORMs – allows you to access and manage databases in an object mode, which speeds up implementation and simplifies the process of loading and saving data.
- The ability to choose formats for configuration files (yaml or xml) – clear and concise presentation.
- The ability to use annotations in controllers to complement configuration files.
- Straightforward configuration of routings and security options (role hierarchy).
- Services that use DI (Dependency Injection) give you easy access to the entirety of functionalities of an app practically from any place.
- Events, listeners and subscribers help you automate business processes. For example, you can set it up so that emails are sent at the time specific data update takes place. These tools are largely practical as well as transparent as far as the working app is concerned.
- Integration with Twig.
Some particularly noteworthy bundles are:
- SwiftmailerBundle – a module that handles email sending in the system.
- JMSI18nRoutingBundle – a module that supports routings in various languages.
- FOSUserBundle – a basic module that allows you to manage users in the system – authorization and permissions.
- FOSMessageBundle – gives you the ability to create and manage messages (useful for blogs or forums).
- KnpSnappyBundle – creates PDF files using the wkhtmltopdf library.
- HWIOAuthBundle – makes it easy to authorize with the most popular social media sites such as Facebook, Google or LinkedIn.
- SonataBundle – a fully functional CMS to manage data in the database. It consists of the following elements: SonataAdminBundle (admin panels for the project entities), ClassificationBundle (category, collection and tag entities that allow you to classify objects), MediaBundle (file upload and management), UserBundle (extends the FOSUserBundle with the CRUD information about the users).
How to convince administrators to use Symfony2?
There is no administrator that wouldn’t value a stable and integrated environment, one that is reliable and doesn’t require them to meddle with it all the time. Symfony2 has a built-in console to issue app-related commands. Basic functionalities can be accessed from the CLI level, which makes management much easier. New commands can be added and the existing ones extended. As a result, the administrator has full and continuous control over the app and can use all of its resources by issuing commands straight from the system environment.
Easy deployment using ready-made modules is yet another important factor. With the Capifony modules, one can easily launch new versions of the app (releases) by manually updating the code, clearing the cache, downloading composer dependencies and management assets.
Thanks to a comprehensive documentation and a large group of programmers from all over the world that constantly work on Symfony2, modules are regularly updated and supported. The long-term support timeframe for the latest versions makes it easy to plan projects and the implementation of functionalities. As of today, the 3.4 version is scheduled to be supported through to 2021.
Furthermore, by using caching for PHP (APC, Opcache), caching for the app itself, Doctorine, support for Sass, Grunt, using filters such as yui (to minimize CSS and JS files), you can make a Symfony2-based app even faster and less resource-heavy.
How to convince project managers to use Symfony2?
The project manager needs an app that is, above anything else, easy to manage and reliable. Each phase of the development process should be possible to plan and not be interfered by human resource management struggles. The modular nature of Symfony2 makes it possible for developers to work on specific functionalities independently. The functional structure of the framework facilitates the introduction of Agile development methodologies and an integrated test environment allows you to write clear and concise code. With extra bundles, you can write complex unit, functional and behavioral tests using PHPUnit, Behat or Selenium. Writing scenarios for behavioral tests becomes quite easy and enjoyable. Such tests can be run via a standard text browser that does it quite fast and consumes little resources or via a full-fledged browser client, using Selenium, which allows you to fully test all of the functionalities of the app as well as its client-side layer (CSS, JS). With access to most of the commands straight from the CLI layer, the integration with a Continuous Integration Server (i.e. Bamboo) is quite easy and the increasingly large number of modules and their straightforward implementation makes it possible to introduce just about any available technology (AngularJS, WebSocket).
How to convince clients to use Symfony2?
Each client values low cost and fast implementation of the projects. As Symfony2 projects are scalable and make it easy for new programmers to adapt, the framework can significantly lower the overall cost. Making use of its versatile and concise mechanisms is a sure way to build an app rapidly from the ground up. The increasing popularity of the framework causes the number of its users to continuously grow. As a result, developing custom- and tailor-made solutions with Symfony2 is easier than with any other similar framework currently available on the market.
Marek Balicki, PHP Developer at Polcode