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

New in Symfony 4.1: Misc. improvements (part 1)

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.

During the past months we've published almost 40 blog posts about the main new features of Symfony 4.1. In this article you'll find some of the other small but nice new features.

Made csrf_token() usable without forms

Contributed by
Christian Flothmann
in #25197.

The csrf_token() Twig function is currently only registered when the Form component is installed. However, this function is also useful, for example, when protecting against CSRF in login forms for which you do not need the full Form component.

In Symfony 4.1, you can use the csrf_token() function even when the Form component is not installed.

CSV processor for env vars

Contributed by
Kévin Dunglas
in #25627.

Although it's not as popular as other formats like JSON and YAML, some apps store their environment variables using the CSV format. In Symfony 4.1 you can use a new csv processor to decode those contents into a PHP array (it uses the str_getcsv() PHP function to do the conversion):

    env(some_parameter): 'foo,bar,baz'
    some_option: %env(csv:some_parameter)%
    # 'some_option' is array('foo', 'bar', 'baz') in the PHP app

Combine this new csv processor with the existing file: processor to parse the CSV encoded env vars stored in some file.

Made ProgressBar::setMaxSteps public

Contributed by
Gabriel Ostrolucký
in #26449.

In Symfony 4.1 this method is public so you can change the progress bar size dynamically while the app is executing. It's useful for edge cases like showing the upload progress of a big file which hasn't been fully downloaded yet:

use Symfony\Component\Console\Helper\ProgressBar;

$bar = new ProgressBar($output);



This example will display the following progress bars in the terminal:

      0 [----------------------------]
      2 [==|-------------------------]
   5/10 [==============|-------------]  50%
 10/100 [==|-------------------------]  10%
100/100 [============================] 100%

Display DotEnv vars in the profiler

Contributed by
Roland Franssen
in #25166.

In Symfony 4.1, the environment variables created by the DotEnv component are now displayed in the profiler separately from the other env vars. That makes it easier to check if your .env config file is working as expected:

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.

New in Symfony 4.1: Misc. improvements (part 1)

Tweet this


Awesome, was hoping we'd have a way to change maxSteps soon.
`some_parameter: 'foo,bar,baz'` should be replaced by `env(some_parameter): 'foo,bar,baz'`, shouldn't it?
@Alex good catch! I've just fixed it. Thanks.
Wow, awesome! Was using the Progressbar in this week and after a quick analyse of the class, I was confused why you couldn't set the maxSteps other than in the constructor.
This is really AWESOME!!!! Thank you everyone for make this the best framework for PHP!!
Great changes guys.
Is it a good idea to expose plain text credentials from .env in this way? Someone looking over your shoulder can read this.
@Tom we think it's OK because the profiler should never be enabled in production (we've always said that and docs also explain that) so you can't see the production secrets, only the irrelevant secrets used in the development environment.

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.