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¶
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.
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):
1 2 3 4 | parameters:
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.
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:
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%
|
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:
What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...