Symfony is an open-source framework that helps developers build complex PHP web applications.
Many of Symfony’s reusable components are included in the Drupal core library. They’re integrated into thousands of projects and have been downloaded billions of times.
It’s not hard to see why—Symfony provides access to clean, stable code that saves developers from having to reinvent the wheel. It promotes decoupled code and invites standardization of best practices. Using Symfony in combination with Drupal helps developers to create more maintainable solutions with superior performance.
The latest version of Symfony—released in November 2022—brings exciting new features for Drupal 10 developers. We shared our top picks below to help you leverage the benefits of Symfony 6.2.
Our Pick of Best New Features in Symfony 6.2
1. PSR-4 Route Loader
This is a fantastic addition that provides a faster, more efficient way of finding route attributes defined in PHP classes. As Symfony is used in Drupal 10 and many other CMSs, a lot of projects should get a nice speed boost.
The new PSR-4 route loader replaces an outdated process, whereby AnnotationDirectoryLoader found PHP files recursively and AnnotationFileLoader inspected their contents. This process became unnecessary for modern PHP projects as they all use PSR-4 class autoloading.
You can implement the new route loader by simply defining the PSR-4 namespace used by your controller classes.
YAML configuration to define the PSR-4 namespace. The namespace option is also supported in XML and PHP configs. Source: Symfony.
2. More Built-In Attributes
Cache, security, templates and Doctrine annotations are core in Symfony 6.2. This is great because it means you no longer have to install SensioFrameworkExtraBundle to use them. In most applications, you’ll simply need to update the imported namespace without having to change anything in your code.
3. New UID Features
Symfony 6.2 has support for UUID Version 7 and UUID Version 8 formats—an addition that should please developers who’ve been concerned about UUID Version 4’s collision chances.
And there are some fresh features in the UID component including:
- MaxUUID and MaxULID– two new classes that represent the highest possible value of both UUID and ULID.
- Time-based UID Interface – makes it easier to get date/time values from UIDs.
- UID Conversion to Hexadecimal Values – the new toHex() method returns the binary value as an hexadecimal string.
Returned hexadecimal strings can be used in other parts of your application, such as querying UIDs in binary format in the database. Source: Symfony.
4. Better Debugging Commands
Symfony 6.2 features improved commands for debugging issues while developing your applications. We particularly appreciate the new --resolve-env option that’s been added to the debug:config command. This new feature hides the secret by default when you're trying to debug variables in the console. It may be useful when recording a training session with live data that you don't want to expose, for example.
5. Redesign of Profiler
Symfony’s Profiler is a powerful development tool that gives detailed information about debugging the execution of any request. Symfony 6.2 features a redesign of profiler that offers a modern look and feel.
Profiler has a fresh coat of paint in Symfony 6.2. Source: Symfony.
More Improvements in Symfony 6.2
That’s not all! We only touched on a handful of the updates and new features in Symfony 6.2. There are many more to get excited about, including:
- Security improvements such as an easier process for logging in users programmatically and customization of the impersonating target URL.
- Better emoji support that lets you slugify and transliterate emojis and their description into any language.
- New clock component to improve the testability of time-sensitive code.
- Finder component improvements to make it easier to sort by file extension, size and case-insensitive name.
- New AST-based translation extractor to find translatable contents in PHP files.
- File constraint improvements that validate both file extensions and media types (MIME types) in a much simpler way.
- PHP Enum support in service parameters, YAML files, and environment variable processors.
- DX improvements such as a simpler way to get the current route in templates and hide sensitive information.
- Console improvements such as improved color support and autocompletion for Zsh shells.
Planning to migrate to Drupal 10?
Explore other relevant resources from Evolving Web:
Evolving Web is a Drupal Certified D7 EOL Migration Partner. We've been supporting organizations through complex migrations since 2007. Partner with us for your move to Drupal 10 and let us do the heavy lifting.