What Is New in Symfony 3.2
Symfony 3.2 introduces a focused set of new components, developer tools, and quality-of-life improvements. This release continues the framework's evolution with an emphasis on modern PHP practices and developer productivity.
| Category | Key Changes |
|---|---|
| New Components | Introduction of the Cache and Workflow components. |
| New Features | PSR-6 caching, a new "recovery" command, and autowiring by type and name. |
| Improvements | Enhanced LDAP component, better PHPUnit bridge, and new form type options. |
| Deprecations | Several legacy methods and patterns are marked for removal in Symfony 4.0. |
What are the major new components in Symfony 3.2?
Symfony 3.2 ships with two brand-new, fully stable components: Cache and Workflow. The Cache component provides a PSR-6 compliant interface with multiple adapters (filesystem, Redis, APCu) for superior performance. The Workflow component allows you to define a lifecycle for your domain models, managing states and transitions in a decoupled way.
In practice, the Cache component standardizes caching across your application, replacing the older Doctrine Cache dependency in many places. The Workflow component is perfect for managing complex processes like order fulfillment or content publishing pipelines.
How does service autowiring get better in this release?
Autowiring in the Dependency Injection component becomes more powerful and precise. Beyond just type-hinting, you can now autowire services by their name. This is done using the autowire attribute in your service definitions within YAML, XML, or PHP configuration files.
services:
App\Mail\NewsletterManager:
autowire: true
# This will automatically inject the service named 'mailer'
arguments:
$mailer: '@mailer'
This reduces manual wiring for common scenarios, making your configuration cleaner and less error-prone. It's a logical step towards the more automated service configuration envisioned for Symfony 4.
What developer tools have been added?
A new recovery command is added to the Symfony Debug component. If a fatal error occurs in a console command, this utility helps you recover by offering to run the last command again with different arguments or options.
This matters because it saves time during development and debugging. Instead of manually re-typing a long command after a failure, you can quickly iterate and test fixes.
Are there improvements for testing and forms?
PHPUnit Bridge
The PHPUnit bridge now provides better error messages when tests fail due to a silenced deprecation notice. It helps pinpoint the exact test and the deprecated feature being used.
Form Component
The Form component gains new options like error_bubbling for the ChoiceType and a choice_loader option for lazily-loaded choice lists. These give you finer control over form behavior and performance.
What should I know about the deprecated features?
Several features are soft-deprecated in 3.2, meaning they will be removed in Symfony 4.0. Key deprecations include the getRootDir() method in the Kernel class and the simple keyword for defining controller routes in YAML/XML.
You should update your code to use the new alternatives, like getProjectDir() and explicit controller/service definitions. Running your application with the Symfony Profiler or the debug:container command will highlight these deprecations.
FAQ
Is the new Cache component a replacement for Doctrine Cache?
Yes, in many Symfony internal contexts. The new Cache component is PSR-6 compliant and is used by the FrameworkBundle for caching templates, translations, and annotations. You should adopt it for new caching needs, but existing Doctrine Cache integrations will still work.
When should I use the new Workflow component?
Use it whenever a model (like a blog post, support ticket, or order) goes through a defined set of states (e.g., draft, review, published). It centralizes the rules for state transitions, making the logic easier to test and modify than if it's scattered across controllers and services.
How does autowiring by name work exactly?
In your service configuration, you can now explicitly map a constructor argument name to a specific service ID using the autowire attribute. The container will resolve and inject the correct service based on that name, not just the type-hint.
What's the main benefit of the new 'recovery' command?
It streamlines the development feedback loop. After a console command crashes, you can immediately re-run it with different parameters without leaving the terminal, which is faster than re-typing the entire command.
Are the LDAP component improvements backward compatible?
Yes, the improvements, which include better connection handling and a new ExtLdap adapter for more advanced use, are fully compatible. They provide more robustness and features without breaking existing implementations.