What Is New in Symfony 2.1
Symfony 2.1 is a significant feature release that introduces new components and major enhancements to existing ones. The table below summarizes the key areas of change.
| Category | Key Changes |
|---|---|
| New Components | Form, Validator, Security (reworked), Finder, Stopwatch, PropertyAccess |
| Core Enhancements | Expression Language, DIC Improvements, New Routing Features |
| Deprecations | Some methods and classes deprecated, paving the way for 2.x |
| Bug Fixes | Numerous fixes across the framework foundation |
What are the major new components in Symfony 2.1?
Symfony 2.1 ships with several brand-new, standalone components. The Form and Validator components are now fully decoupled from the framework core, meaning you can use them in any PHP project. This separation was a major architectural shift.
The Security component was almost entirely rewritten for greater flexibility and power. New utility components like Finder (for file system operations) and Stopwatch (for profiling) were introduced, expanding Symfony's toolkit for common development tasks.
How did the Form component improve in version 2.1?
The Form component became a standalone library with a more flexible architecture. A key addition was the PropertyAccess component, which provides a unified way to read and write object/array properties and is used extensively by the Form layer.
Form themes became more powerful with the introduction of theme inheritance. You could now create a base form theme and extend it for specific forms, reducing duplication in your Twig templates significantly.
What routing features were added?
Routing gained the ability to match and generate URLs with non-string parameters, like integers or arrays. This was crucial for advanced use cases, especially when integrated with the new Expression Language support.
The new _format routing parameter became a first-class citizen. It allows you to define the expected response format (like json, xml, html) directly in the route pattern, simplifying content negotiation logic in controllers.
What is the Expression Language and where is it used?
The Expression Language is a compact, powerful language for evaluating expressions, integrated directly into the Dependency Injection Container (DIC) and Security components. In practice, it lets you define complex logic in configuration using a simple syntax.
For security, you can use expressions in access controls. For example, you can write rules like is_granted('POST_EDIT') and user == post.getAuthor() directly in your security configuration, moving complex authorization logic out of your controllers.
How did the Dependency Injection Container evolve?
The DIC introduced expression support for service definitions, allowing dynamic behavior based on configuration. You could now use the Expression Language to conditionally inject services or parameters.
It also added the concept of "lazy services" using proxy managers. This means a service that is expensive to instantiate is only fully created when one of its methods is actually called, which can improve performance on specific workflows.
FAQ
Is the new Form component backwards compatible with Symfony 2.0?
Mostly, but not entirely. While the core concepts remain, the decoupling and internal refactoring introduced some breaking changes. You'll need to update form type classes and check your templates, especially if you used advanced features.
Can I use the standalone Form component in a non-Symfony project?
Absolutely. That was a primary goal of the 2.1 refactoring. You can install it via Composer and use it in any PHP application, which increased its adoption across the ecosystem.
What happened to the old Security component?
It was completely rewritten. The new component offers a more granular, voter-based access decision system which is far more flexible. This means upgrading requires revisiting and likely rewriting your security configuration and custom providers.
Why was the Stopwatch component added?
It provides a standardized way to profile your application's execution time for specific sections of code. It's used internally by the Symfony Profiler but is also available for developers to instrument their own business logic.
Are there any significant deprecations I should be aware of?
Yes, several methods, especially in the HttpFoundation and Routing components, were marked as deprecated. For instance, some methods in the Request class were deprecated in favor of using the ParameterBag objects directly. The release notes contain a full list.