The ExpressionLanguage component provides an engine that can compile and evaluate expressions. The main purpose of this component is to use expressions inside configuration for more complex logic. Its other purpose is to use it to build business rule engines. In Symfony 6.1 we're improving the already rich ExpressionLanguage syntax with more features.
New Syntax Options for Numbers
Contributed by Thomas Calvet
in #44073.
In order to better align with the expressions supported in modern PHP code, you can now define numbers using the following syntax:
# you can remove the leading zero of decimal numbers (in previous versions you had to use 0.99)
$expressionLanguage->evaluate('product.price 1_000_000', ['...' => '...']) $expressionLanguage->evaluate('2 3.14159_26535 radius', ['...' => '...'])
New Operators
Contributed by Fabien Potencier
and Sofien Naas
in #45912, #45795.
First, we've added a new ?. operator which is equivalent to the PHP null-safe operator. It prevents errors when trying to access a property or method of an object that is null:
// this will throw an exception when `fruit` is `null`
$expressionLanguage->evaluate('fruit.color', ['fruit' => '...'])
// this will return null
if fruit
is null
$expressionLanguage->evaluate('fruit?.color', ['fruit' => '...'])
In addition to the null-safe operator, we've added three new operators (contains, starts with and ends with) that allow to create very readable expressions:
$expressionLanguage->evaluate('coupon.code stars with "XXX"', ['...' => '...'])
$expressionLanguage->evaluate('imported_file.path ends with ".csv"', ['...' => '...']) $expressionLanguage->evaluate('url contains "example.com"', ['...' => '...'])
These operators were already available in Twig templates, making ExpressionLanguage component more in sync with Twig.
Sponsor the Symfony project.
Zaloguj się, aby dodać komentarz
Inne posty w tej grupie

SymfonyLive Paris 2025, conference in French language only, will take place from March 27 to 28! The schedule is currently being revealed as we go along. More details are available here. 🚨 Tod

Symfony 6.4.19 has just been released. Here is the list of the most important changes since 6.4.18:
bug #59198 [Messenger] Filter out non-consumable receivers when registering ConsumeMessagesComm

Symfony 7.2.4 has just been released. Here is the list of the most important changes since 7.2.3:
bug #59198 [Messenger] Filter out non-consumable receivers when registering ConsumeMessagesComman

SymfonyLive Paris 2025, conference in French language only, will already start in 1 month with the workshops! Have a look on the topics and join us! Schedule details are available here.
📣

A few weeks ago, I had the pleasure of announcing the formation of the Symfony UX Core Team, a dedicated group working to enhance the frontend development experience within the Symfony ecosystem. Toda

SymfonyLive Paris 2025, conference in French language only, will take place from March 27 to 28! The schedule is currently being revealed as we go along. More details are available here.
Al

This week, development activity focused on new security features. The upcoming Symfony 7.3 version added support for security voters to explain their vote, improved the IsGranted attribute to allow us