an introduction to symfony 2 for symfony 1 developers
TRANSCRIPT
An introduction to symfony 2 for symfony 1 developers
By Giorgio Cefaro
What is Symfony 1?
Symfony is a full-stack framework, a library of cohesive classes written in PHP.
It provides an architecture, components and tools for developers to build complex web applications faster.
from symfony-project.com
What is Symfony 2?
First, Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP components that solve common web development problems.
Then, based on these components, Symfony2 is also a full-stack web framework.
I don't like MVC because that's not how the web works. Symfony2 is an HTTP framework; it is a Request/Response framework. That's the big deal. The fundamental principles of Symfony2 are centered around the HTTP specification.
from F. Potencier blog http://fabien.potencier.org/article/49/what-is-symfony2
Directory structure
Symfony 1.4
Symfony 2
General architectural differences
Symfony 1.4Full stack MVC framework
Complex controller layer
Multi-application architecture
Application/plugin level routing
Code organized in applications/modules and plugins
Symfony 2Full stack MVC decoupled components bundled in a framework, fully HTTP compliant
Simpler Controller objects
Single application
Global routing
Code organized in bundles
A bundle is like a symfony 1 plugin
Even Symfony 2 core components are distributed as bundles
Controller
Symfony 1Complex and coupled Controller Layer
Not fully replaceable (ok, let's say heavy hacking needed!)
Distributed over applications, plugins, modules, filters...
Dirty mix of routing patterns and straight module access
Symfony 2A controller can be easy as a simple PHP function
A base Controller class is supplied with several helper methods and can be used as standalone component
No routing, no party! Access to controller actions inside bundles MUST go through routing pattern matching
Configuration
Symfony 1.4Configuration Cascade
Lots of yml files (app, factories, database, security, cache, etc ) distributed through apps, plugins and modules
You can get easily lost in a complex situation
Symfony 2Configuration files inside blundles must be included manually from outside
Less configuration files
The sole config.yml is incredibly powerful
With config.yml and routing.yml you can do almost everything :-)
Handling Dependencies
Symfony 1.4Dependency handling is left to the developer
Service configuration limited to standard components
All mixed up in factories.yml
Non standard services if not properly handled may easily introduce coupling and poor testability
Symfony 2Service Container
Dependency Injection for full decoupling and high testability
Public and private services, tags, aliases
Handling Dependencies mailer example
Symfony 1.4
Symfony 2
Validation
Symfony 1.4Embedded inside forms
Validators are not easily reusable in other contexts (for example webservices)
Symfony 2Validators are sticked to Entities
Configurable via Yaml, xml, annotations or PHP
Validators are called via the Service Container
Validation
Symfony 1.4
Symfony 2
Persistence - Doctrine
Symfony 1.4Bundled with the framework as a standard (with Propel as an alternative)
Active Record
Design requires lot of effort to make code fully testable
Symfony 2Totally decoupled from the framework via Service Container
Entities are independent from OR[D]M
Entities are mapped to DB via metadata definition (Yaml, xml, or annotations)
Persistence - Doctrine
Symfony 1.4
schema.yml
Symfony 2
Product.orm.yml
Persistence - Doctrine
Symfony 1
Symfony 2
Cache
Symfony 1.4Non-standard cache mechanism, though flexible and configurable
Symfony 2Standard RFC 2616 HTTP Cache
Testing
Symfony 1.4Lime framework bundled as a standard, PHPUnit can be used as a plugin
Lime is not as powerful as PHPUnit
Symfony 2Fully integrated with PHPUnit framework
In functional tests internal objects can be fully inspected (kernel and DI container too!)
Should I move to Symfony 2?
Yes.
Giorgio Cefaro
Twitter: @giorrrgiolinkedin.com/in/giorgiocefaro