New in Symfony 5.4: Misc. features (part 2)

Configurable Status Code in Templates Rendered From Routes

        Contributed by Dale Nash 
        in #41414.

In Symfony applications controllers render templates most of the times. However, you can also render templates from routes config for simple cases where creating a controller would be unnecessary. In Symfony 5.4 we're improving this feature to allow you define the HTTP status code of the response that contains the rendered template (to override the default 200 status applied to these responses):

    1

2 3 4 5 6 7

config/routes.yaml

upload_started: path: /upload_started.html controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController defaults: template: 'file_upload/started.html.twig' statusCode: 202 # HTTP Status = Accepted

New innerText() Method in DomCrawler

        Contributed by Bilge 
        in #42338.

The Symfony DomCrawler component eases DOM navigation for HTML and XML documents. In Symfony 5.4 we're improving it with a new innerText() method. It's similar to text() but it only returns the text that is the direct descendant of the current node, excluding any child nodes:

    1

2 3 $text = $crawler->filterXPath('//body/p')->innerText(); // if content is Foo Bar // innerText() returns 'Foo' and text() returns 'Foo Bar'

Recursive .gitignore Support in Finder

        Contributed by Julien Falque 
        in #43150
        and #43837.

The Symfony Finder component allows you to apply the .gitignore rules of the directory where you are searching. This way you don't need to repeatedly exclude some files or directories from the search:

    1

2 3 // if .gitignore file exists in the directory, its contents // are parsed and applied to the file/dir search $finder->ignoreVCSIgnored(true);

In Symfony 5.4 we've improved this feature to better align with Git's default behavior. When enabling this feature, the Finder component will use the .gitignore files of all subdirectories traversed during the search. Also, the rules of subdirectories always override the parent directories rules.

New Command to Debug Environment Variables

        Contributed by Christopher Hertel 
        in #42580.

Configuration based on environment variables is increasingly popular in Symfony applications. Given that many different files can define and override those env vars, in Symfony 5.4 we've added a new debug:dotenv command to help you debug the value of all your env vars and which .env files were checked:

                Sponsor the Symfony project.

https://symfony.com/blog/new-in-symfony-5-4-misc-features-part-2?utm_source=Symfony%20Blog%20Feed&utm_medium=feed

Établi 3y | 2 déc. 2021 à 11:20:09


Connectez-vous pour ajouter un commentaire

Autres messages de ce groupe

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
Symfony 7.2.3 released

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

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

bug #59631 [HttpClient]

29 janv. 2025 à 09:40:04 | Symfony
SymfonyLive Paris 2025 : Développer plus vite grâce à FrankenPHP

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.

Al

28 janv. 2025 à 08:10:10 | Symfony