systopia / expression-language-ext
Extension for the Symfony ExpressionLanguage Component
Installs: 10 920
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8
- symfony/expression-language: ^5 || ^6 || ^7
README
This is an extension for Symfony's ExpressionLanguage component. It provides the functions date_create and map as well as different PHP functions. For simplified use all those functions are available in the class SystopiaExpressionLanguage.
date_create
Function
The date_create
function creates an object of type \DateTimeImmutable
by
using the default constructor.
Example:
$expressionLanguage = new SystopiaExpressionLanguage(); $dateTime = $expressionLanguage->evaluate('date_create("2000-01-02 03:04:05")');
map
Function
The function map
allows to apply an expression to the values of an array
(actually any iterable). Each pair of key and value are provided as variables
named key
and value
to the expression.
Example:
$array = [ 'x' => (object) ['a' => 1, 'b' => 2], 'y' => (object) ['a' => 3, 'b' => 4], ]; $expressionLanguage = new SystopiaExpressionLanguage(); $mapped = $expressionLanguage->evaluate( 'map(array, "key ~ \": \" ~ (value.a + value.b)")', ['array' => $array] ); var_dump($mapped);
Output:
array(2) {
[0]=>
string(4) "x: 3"
[1]=>
string(4) "y: 7"
}