Right now the Symfony blog is publishing interesting articles on the new features of version 5.2; at dotenv we pay close attention to this news, as regular users of the latest software versions.
With Symfony, versions are usually released up to .4 (so, in this case, 5.4), which will become the LTS (Long Term Support), before moving on to version 6; up to 5.4 it is therefore fair to expect new features on top of the usual bug fixes. You will find more information on the Symfony release cycle below.
Session Profiling
Symfony Profiler is a very useful tool for debugging web pages properly; it lets us view information such as the number of database queries, response times and now (at last) session information too. For information: Article and Pull Request.
PHP 8 attributes
We talked about some of the new features of PHP 8 in this article on our blog, but we deliberately left out one new feature that goes very well with Symfony: attributes. Usually, in fact, information such as Routes or the instructions on how to build tables for Doctrine is written in so-called annotations:
// BEFORE: annotations defined with Doctrine Annotations library
use SymfonyComponentRoutingAnnotationRoute;
class SomeController
{
/**
* @Route("/path", name="action")
*/
public function someAction()
{
// ...
}
}
In this example, the “SomeController” controller will respond with the “someAction” action when the user calls the “/path” url; this could be a web page or an API. In PHP8, with the new annotations, we can replace the Route, which will become:
// AFTER: annotations defined with PHP 8 attributes
use SymfonyComponentRoutingAnnotationRoute;
class SomeController
{
#[Route('/path', name: 'action')]
public function someAction()
{
// ...
}
}
The most interesting thing is that, in the coming weeks, support will be added for many other annotations, including validation. For information: Article and Pull Request 1 and 2.
Doctrine types for UUID and ULID
Something we use a great deal is UUIDs: these are random (or pseudo-random) alphanumeric strings that uniquely identify an item; the most interesting thing is the portability of the data from one system to another. They are not, in fact, AutoIncrement values like the classic IDs of every database.
To generate these UUIDs we can usually use two systems: use the Polyfill or packages such as ramsey/uuid
In Symfony 5.2 we will have native support and will therefore be able to write Entities like this:
// src/Entity/Product.php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass="AppRepositoryProductRepository")
*/
class Product
{
/**
* @ORMColumn(type="uuid")
*/
private $someProperty;
/**
* @ORMColumn(type="ulid")
*/
private $anotherProperty;
// ...
}
This will save us from adding a new dependency to the project and, above all, will make everything much more readable. For information: Article and Pull Request
True colors in the console
To finish, a purely “stylistic” feature, useful above all when you use Symfony to create commands to be used in the console: support for 24-bit colours is coming
// using a predefined style
$output->writeln('<info>... contents ...</>');
// custom style using basic colors
$output->writeln('<fg=green;bg=blue>... contents ...</>');
// custom style using true colors
$output->writeln('<fg=#00ff00;bg=#00f>... contents ...</>');
For more information: Article and Pull Request.
We are sure that more interesting news will come out in the coming weeks!
Stay tuned.