DX (developer experience) is defined by the tools, processes, and software that a developer uses when interacting with a product or system. In Symfony we're constantly improving DX and in this post we highlight some of the best Symfony 6.3 DX improvements.
Add Current Locale to the App Variable
In Symfony there's no simple way to get the current locale of the application from Twig templates. You can use the locale switcher introduced in Symfony 6.1 to pass the locale as a template variable.
In Symfony 6.3, we're improving the global app variable to provide direct access to the current application locale:
1
{{ app.locale }}
Dump YAML Numeric Keys as Strings
By default, the Yaml Component dumps digit-only array keys as integers. However, sometimes you are required to use strings as keys (e.g. the OpenApi specification requires that).
In Symfony 6.3, you can use the new Yaml::DUMP_NUMERIC_KEY_AS_STRING
flag
to dump those numeric keys as strings:
1 2 3 4 5
$dumped = Yaml::dump([200 => 'foo']);
// 200: foo
$dumped = Yaml::dump([200 => 'foo'], flags: Yaml::DUMP_NUMERIC_KEY_AS_STRING);
// '200': foo
Easier Way to Delete All Cache Pools
In Symfony 6.3 we've added a new --all
argument to the command that clears
the contents of the cache pools so you can clear them all at once:
1
$ php bin/console cache:pool:clear --all
Automatic Deletion of Expired Profiles
We all love the Symfony profiler for all the debugging information that it gives us while developing applications. But that comes at a price: the profiler information is stored in files that can quickly take a lot of disk space.
In Symfony 6.3 we've introduced a feature to automatically delete profiles after some time. In practice, on each request there's a 10% random chance that Symfony activates the deletion feature. When it's activated, any profile created two days ago or earlier is deleted.
Add Labels to Dump Functions
The dump functions dump()
and dd()
are utilities provided by Symfony
when you quickly need to debug some issue and don't require to use a full debugger.
In Symfony 6.3 we've improved those functions so you can add argument names to
them. Those argument names are later displayed as labels next to the dumped contents:
1 2 3 4 5 6 7
{# Before: #}
{# It was common to use regular strings to add some context information #}
{{ dump('Original order', $order, 'Processed order', $processedOrder) }}
{# After #}
{# The name of the arguments is displayed as labels next to the dumped contents #}
{{ dump(original: $order, processed: $processedOrder) }}
According to "Add Labels to Dump Functions"
The idea is epic 🚀
I tried this starting with
BETA1
and it works fine as long assymfony/debug-bundle
is not installed. I suppose it will after final6.3
release.On the other hand, how can I use this in twig templates?
In article it looks like it is in twig template, but
{{ dump(value: value) }}
causes "punctuation" SytaxError
I use the following syntax for adding labels/context to the dump values:
dump(['original order' => $order, 'processed order' => $processedOrder]);
The feature is really cool. What I would like even more, if the dump shows me at the same time where the dump takes place. So the file and the line. So that I can find my dumps again.
Are there perhaps already plans for this?
@Falko Hilbert, this is already available if you hover over the "^" symbol in front of the dump (this also works when your terminal supports links). The var dumper server also shows the position of the dump calls (https://symfony.com/doc/current/components/var_dumper.html#the-dump-server).