New in Symfony 6.1: Misc. Improvements

Symfony 6.1 has just been released. During the past weeks we've published lots of articles about the most important Symfony 6.1 features. In this article, the last one in the Symfony 6.1 series, we showcase some minor but interesting features introduced by Symfony 6.1.

Configure the Deprecation Messages to Ignore

        Contributed by Mondrake
         in #45226.

If your application has some deprecations that you can't fix yet for some reasons, you can tell Symfony to ignore them. First, create a text file where each line is a deprecation to ignore defined as a regular expression:

    # tests/baseline-ignore.txt

%The "PHPUnit\Framework\TestCase::addWarning()" method is considered internal%

Then, you can run the following command to use that file and ignore those deprecations:

    $ SYMFONY_DEPRECATIONS_HELPER='ignoreFile=./tests/baseline-ignore.txt' ./vendor/bin/simple-phpunit

Allow to Exclude Services from Tagged Iterators and Locators

        Contributed by Ruud Kamphuis
         in #44774.

When working with the Delegation pattern or the Chain-of-responsibility pattern it's common that the service that gets a list of services implementing a certain interface, to also implement that interface itself. For example, in Symfony, the ChainCacheClearer class implements CacheClearerInterface and calls a list of services implementing CacheClearerInterface. In those cases you cannot use autowiring because the main service would receive it itself in the list of services implementing the interface. In Symfony 6.1 we've improved TaggedIterator and TaggedLocator to allow you exclude some services via the new exclude option:

    final class DelegatingErrorTracker implements ErrorTracker

{ public function __construct(

[TaggedIterator(ErrorTracker::class, exclude: self::class)]

    private iterable $trackers
) {}

public function trackError(string $error): void
{
    // ...
}

}

Use Route Parameters in Route Conditions

        Contributed by HypeMC
         in #46042.

Symfony provides a powerful feature to define route conditions as expressions. In Symfony 6.1 we've improved it so you can use the matched route parameters in the expression that is evaluated to decide if the route matches or not. Use the new params variable and pass the name of the route parameter that you want to get:

    class FooController

{

[Route('/foo/{id}', requirements: ['id' => '\d+'], condition: "params['id'] < 100")]

public function index(int $id): Response
{
    // ...
}

}

Support Canners in Object Normalizer

        Contributed by Rokas Mikalkėnas
         in #45282.

Currently, the Serializer component can normalize properties with methods that start with get, set, has, is, add or remove (e.g. getUser(), isPublished(), addCategory(), etc.) In Symfony 6.1, the Serializer will also be able to normalize "canner methods", which are those that start with the can prefix (e.g. canPublish(), canApprove(), etc.)

Detailed Checks for Collection Items Uniqueness

        Contributed by Wojciech Kania
         in #42403.

When combining the Unique constraint with the Collection constraint, all the properties of the collection elements are checked to be unique. In Symfony 6.1 we've improved the Unique constraint to allow defining which collection fields should be checked for uniqueness. The following example validates that each translation of the same resource must be in a different language:

    use Symfony\Component\Validator\Constraints as Assert;

[Assert\Count(min: 1)]

[Assert\Unique(fields: ['language'])]

[Assert\Collection(fields: [

'language' => [
    new Assert\NotBlank,
    new Assert\Length(min: 2, max: 2),
    new Assert\Language,
],
'title' => [
    new Assert\NotBlank,
    new Assert\Length(max; 255),
],
'description' => [
    new Assert\NotBlank,
    new Assert\Length(max: 255),
],

])] public array $translations = [];

A Command to Invalidate Cache Tags

        Contributed by Kevin Bond
         in #44692.

Using cache tags is a way to group different cache items based on arbitrary criteria so you can later invalidate those items more efficiently. In Symfony 6.1 we've added a new cache:pool:invalidate-tags command so you can invalidate those cache tags directly in the command line:

    # invalidate `tag1` and `tag2` from all pools

$ php bin/console cache:pool:invalidate-tags tag1 tag2

invalidate tag1 and tag2 only from a specific pool

$ php bin/console cache:pool:invalidate-tags tag1 tag2 --pool=cache.app

                Sponsor the Symfony project.

https://symfony.com/blog/new-in-symfony-6-1-misc-improvements?utm_source=Symfony%20Blog%20Feed&utm_medium=feed

Établi 3y | 27 mai 2022 à 09:20:09


Connectez-vous pour ajouter un commentaire

Autres messages de ce groupe

Back on the inspiring SymfonyCon Vienna 2024!

We were absolutely thrilled to gather with the incredible Symfony community for the first time in Vienna, Austria, from December 5th to 6th, surrounded by the warm and festive atmosphere of the

31 janv. 2025 à 12:30:18 | Symfony
SymfonyLive Paris 2025 : Reveal of workshop topics!

SymfonyLive Paris 2025, conference in French language only, will take place from March 27 to 28! The schedule is currently being revealed as we go along. More details are available here.

💻

30 janv. 2025 à 08:50:03 | Symfony
Get Symfony news on your favorite social network

Symfony has been active on X, Mastodon, and Bluesky for some time, but until recently, not all platforms received equal attention. Since Twitter (now X) was our first social network, all blog posts we

29 janv. 2025 à 14:20:10 | Symfony
SymfonyLive Berlin 2025: Demystify the magic of the Container

SymfonyLive Berlin 2025, conference held in English, will take place from April 1 to 4! The schedule is being revealed gradually. More details are available here.

As we are now unveiling th

29 janv. 2025 à 14:20:10 | Symfony
Twig CVE-2025-24374: Missing output escaping for the null coalesce operator

Affected versions

Twig versions >=3.16.0,<3.19.0 are affected by this security issue.

The issue has been fixed in Twig 3.19.0.

Description

When using the null coalesce operator (??), output esc

29 janv. 2025 à 09:40:06 | Symfony
Symfony 6.4.18 released

Symfony 6.4.18 has just been released. Here is the list of the most important changes since 6.4.17:

bug #58889 [Serializer] Handle default context in Serializer (@Valmonzo)

bug #59631 [HttpClient

29 janv. 2025 à 09:40:05 | Symfony
Symfony 7.1.11 released

Symfony 7.1.11 has just been released. Here is the list of the most important changes since 7.1.10:

bug #58889 [Serializer] Handle default context in Serializer (@Valmonzo)

bug #59631 [HttpClient

29 janv. 2025 à 09:40:05 | Symfony