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

Created 3y | Dec 2, 2021, 11:20:09 AM


Login to add comment

Other posts in this group

SymfonyLive Paris 2025: See you next week!

SymfonyLive Paris 2025, conference in French language only, is just around the corner! Next week, we’ll come together for an exciting event featuring brand-new talks, inspiring speakers, and e

Mar 20, 2025, 3:30:20 PM | Symfony
A Week of Symfony #950 (March 10–16, 2025)

This week, the upcoming Symfony 7.3 version updated lazy services to use PHP native lazy objects and added a feature to define global translation parameters. Meanwhile, the existing Symfony versions f

Mar 16, 2025, 11:50:02 AM | Symfony
In Paris or Berlin - Take the lightning talks challenge!

SymfonyLive Paris 2025 (March 27 – 28) and SymfonyLive Berlin 2025 (April 3 – 4) are fast approaching! While an incredible lineup of speakers and topics has already been announced, you still have a ch

Mar 13, 2025, 2:10:42 PM | Symfony
SymfonyLive Berlin 2025: Running Symfony in a Multi-Process 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.

We’re thrilled to announce

Mar 11, 2025, 3:30:03 PM | Symfony
A Week of Symfony #949 (3-9 March 2025)

This week, the upcoming Symfony 7.3 version renamed the JsonEncoder component to JsonStreamer, added support for Valkey schemes in the Cache component and introduced a field_id() form helper.

Symfony

Mar 9, 2025, 10:10:11 AM | Symfony
SymfonyLive Paris 2025 : Où sont passées les femmes de l'histoire de la tech ?

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

Mar 7, 2025, 11:40:12 AM | Symfony
SymfonyLive Berlin 2025: CI in PHP Projects: Automate Everything with Your Personal Army of Robots

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.

We’re thrilled to announce

Mar 5, 2025, 8:40:26 AM | Symfony