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.
csrf_token() usable without forms
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
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
str_getcsv() PHP function to do the conversion):
1 2 3 4
parameters: 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.
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:
1 2 3 4 5 6 7 8 9 10 11 12
use Symfony\Component\Console\Helper\ProgressBar; $bar = new ProgressBar($output); $bar->start(); $bar->setProgress(2); $bar->setMaxSteps(10); $bar->setProgress(5); $bar->setMaxSteps(100); $bar->setProgress(10); $bar->finish();
This example will display the following progress bars in the terminal:
1 2 3 4 5
0 [----------------------------] 2 [==|-------------------------] 5/10 [==============|-------------] 50% 10/100 [==|-------------------------] 10% 100/100 [============================] 100%
Display DotEnv vars in the profiler
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.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.