Hands-On With Drupal 10: Symfony 6.2, the New Tech Stack

Recursos
reading time 5
Image
Hands-On With Drupal 10: Symfony 6.2, the New Tech Stack

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.

So it’s no surprise that Drupal has chosen to integrate Symfony even more tightly. Drupal 10 relies on Symfony 6.2 as its underlying technology stack. 

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.

Image removed.

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.

Image removed.

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.