Symfony 6 Certification New exam with updated questions 100% online Show your expertise

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

Symfony 5.4 is backed by Private Packagist. Private Packagist is a fast, reliable, and secure Composer repository for your private packages. It mirrors all your open-source dependencies for better availability and monitors them for security vulnerabilities.

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):

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

New innerText() Method in DomCrawler

Contributed by
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:

$text = $crawler->filterXPath('//body/p')->innerText();
// if content is <p>Foo <span>Bar</span></p>
// 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:

// if .gitignore file exists in the directory, its contents
// are parsed and applied to the file/dir search

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:

Symfony 5 4 Dotenv Debug Command
Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


Glad the `debug:dotenv` is left in the container only if someone uses Dotenv component.
Login with SymfonyConnect to post a comment