New in Symfony 6.3: DX Improvements (Part 1)
May 12, 2023 • Published by Javier Eguiluz
Symfony 6.3 is backed by:
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
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) }}
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.
The idea is epic 🚀
I tried this starting with `BETA1` and it works fine as long as `symfony/debug-bundle` is not installed.
I suppose it will after final `6.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
`dump(['original order' => $order, 'processed order' => $processedOrder]);`
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?