New in Symfony 6.4: DX Improvements (part 1)

ISO 3166-1 Numeric Codes Support

Contributed by
Ben Roberts

in #51073.

The Intl component provides access to the 2-letter and 3-letter alphabetic codes
that represent countries, dependent territories, and special areas of geographical
interest. However, the alphabetic codes use the 26-letter English alphabet, which
might be unavailable or difficult to use for people and systems using non-Latin
scripts (e.g. Arabic or Japanese).

That’s why in Symfony 6.4 we’re adding support also for the ISO 3166-1 numeric standard,
which represent each country/territory with a 3-digit integer. For example,
Singapore is SG (ISO 3166-1 alpha-2), SGP (3166-1 alpha-3) and 702
(ISO 3166-1 numeric).

Improve Type Constraint

Contributed by
Guillaume A.

in #50907.

The Type constraint validates that the given value is of a specific data type
(e.g. callable, numeric, countable, double, etc.) In Symfony 6.4
we’re improving it with three new types:

finite-float;
number, a finite or infinite integer or float;
finite-number, a finite integer or float.

You can combine these new types with any of the other existing types:

#[AssertType([‚int‘, ‚finite-float‘])]
private $value;

Custom Precision when Formatting Time Messages in Console

Contributed by
Maximilian Beckers

in #50537.

The time formatting utilities provided by the Console component are useful
to display the elapsed or remaining time in progress bars, etc. In Symfony 6.4
we’re improving those utilities so you can set the precision used to render the time.
This precision is an integer that tells how many parts of the time (days, hours, etc.)
should be displayed.

Helper::formatTime(172799, 1); // 1 day
Helper::formatTime(172799, 2); // 1 day, 23 hrs
Helper::formatTime(172799, 3); // 1 day, 23 hrs, 59 mins
Helper::formatTime(172799, 4); // 1 day, 23 hrs, 59 mins, 59 secs

Early Directory Pruning

Contributed by
Michael Voříšek

in #50877.

The Finder component provides many utilities to find files and directories
based on certain conditions. One of those utilities is the filter() method,
which allows to exclude directories from the result.

In Symfony 6.4 we’re adding a second optional argument to filter() which allows
you to prune directories early instead of excluding them. This can improve performance
significantly because pruning means that those directories are completely skipped
instead of traversing the entire file/directory structure and excluding them later.

New Methods to Render Blocks from Controllers

Contributed by
Nicolas Grekas

in #51327.

The AbstractController class in an optional base controller that provides
utilities commonly needed in your own controllers. In Symfony 6.4 we’re improving
it with two new methods:

renderBlock(), renders the given Twig block from a template and returns
a Response object;
renderBlockView(), renders the given Twig block from a template and returns
the contents as a string variable.

These methods come in handy e.g. when generating turbo stream responses:

// Before
return new Response(
$this->container->get(‚twig‘)->load(‚foo.html.twig‘)->renderBlock(‚the_block‘, $context)
);

// After
return $this->renderBlock(‚foo.html.twig‘, ‚the_block‘, $context);

Sponsor the Symfony project.

Symfony Blog

Read More

Latest News

PHP-Releases

PHP 8.4.1 released!

PHP 8.1.31 released!

PHP 8.3.14 released!

PHP 8.2.26 released!

Generated by Feedzy