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.
Ak chcete pridať komentár, prihláste sa
Ostatné príspevky v tejto skupine

At Wide, Micropole’s digital agency, they help leading brands modernize their digital infrastructures while ensuring scalability, security, and performance. When Audi France approached them to migrate

Vente-unique.com, a leading European online retailer of furniture and home decor, operates in 11 countries, powered by a team of 400 professionals and serving more than 3 million customers. From 15 ye

This week, Symfony 6.4.23, 7.2.8 and 7.3.1 maintenance versions were released. Meanwhile, the upcoming Symfony 7.4 version continued adding new features such as better controller helpers, more precisi

Symfony 6.4.23 has just been released. Read the Symfony upgrade guide to learn more about upgrading Symfony and use the SymfonyInsight upgrade reports to detect the code you will need to change in you

Symfony 7.2.8 has just been released. Read the Symfony upgrade guide to learn more about upgrading Symfony and use the SymfonyInsight upgrade reports to detect the code you will need to change in your

Symfony 7.3.1 has just been released. Read the Symfony upgrade guide to learn more about upgrading Symfony and use the SymfonyInsight upgrade reports to detect the code you will need to change in your

This week, development activity was intense, with many bug fixes in the maintained branches, numerous deprecation removals in the 8.0 branch, and new features added to the 7.4 branch, including tighte