New in Symfony 6.3: DX Improvements (Part 2)
DX (developer experience) improvements are small changes that make your
day-to-day work as developer easier or more pleasant. A few days ago we published
the first DX improvements of Symfony 6.3 and this blog post shows other DX
improvements added by Symfony 6.3.
Display Invisible Characters in Dumped Contents
Contributed by
Antoine Lamirault
in #48748.
Unicode defines tens of different invisible characters like white spaces. These
characters are problematic because they can result in impossible to debug issues
where e.g. two strings look identical but your code says that they are not the same.
In Symfony 6.3 we’re improving the VarDumper component to always highlight the
invisible characters of the contents. For example, if the string Lorem Ipsum
contains a zero-width non-breaking space (Unicode character U+FEFF) after the
letter o, you’ll see this: Lou{FEFF}rem Ipsum.
Allow Milliseconds and Microseconds in YAML Dates
Contributed by
Dustin Wilson
in #49164.
The Yaml Component can process dates with milliseconds/microseconds but that
information is lost when dumping the dates again. In Symfony 6.3, we’re improving
the Yaml dumper to detect if the dates have that information. This new behavior
is automatic, so you don’t need to add any config flag to the ->dump() call:
// BEFORE
date: 2023-01-08T16:18:25Z
# dumped as: 2023-01-08T16:18:25+00:00
date_with_milliseconds: 2023-01-08T16:18:25.213Z
# dumped as: 2023-01-08T16:18:25+00:00
date_with_microseconds: 2023-01-08T16:18:25.718800Z
# dumped as 2023-01-08T16:18:25+00:00
// AFTER
date: 2023-01-08T16:18:25Z
# dumped as: 2023-01-08T16:18:25+00:00
date_with_milliseconds: 2023-01-08T16:18:25.213Z
# dumped as: 2023-01-08T16:18:25.213+00:00
date_with_microseconds: 2023-01-08T16:18:25.718800Z
# dumped as: 2023-01-08T16:18:25.718800+00:00
Build Parameters in Service Container
Contributed by
Jules Pietri
in #47680.
The Service Container compilation is one of the most critical parts of a
Symfony application. It allows to build and optimize the services/parameters of
your applications and it’s the reason why Symfony is so fast.
During the compilation phase, it’s common to create temporary parameters in the
container that you later delete when the compilation is finished. That’s why in
Symfony 6.3 we’ve introduced build-only parameters. Prefix your parameter name
with a dot (e.g. .name) and it will be automatically removed when the compilation
finishes:
// normal parameter (you can delete it manually if you want)
$containerBuilder->setParameter(‚foo‘);
// this won’t be available in the built container (it’s deleted after the compilation)
$containerBuilder->setParameter(‚.bar‘);
Streamed JSON Responses
Contributed by
Alexander Schranz
in #47709.
When you stream lots of data via a JSON API, it’s difficult to keep low the
consumption of resources such as memory. In Symfony 6.3 we’re introducing a
new StreamedJsonResponse that uses a structure and generics to create an
efficient resource-saving JSON response.
Imagine that you have a content generator like this:
public function loadArticles(): Generator
{
// generate contents somehow…
yield [‚title‘ => ‚Article 1‘];
yield [‚title‘ => ‚Article 2‘];
yield [‚title‘ => ‚Article 3‘];
// it’s recommended to use flush() after every specific number of items
}
In Symfony 6.3, you can use the following in your controller to stream these
JSON contents:
return new StreamedJsonResponse([
‚_embedded‘ => [
‚articles‘ => loadArticles(),
],
]);
That’s all. Symfony will take care of all the needed logic to stream this efficiently.
Symfony Blog