What is it ?
This package extends the ExpressionLanguage component of Symfony to compile and evaluate arrays with custom functions.
Installation
composer require php-etl/array-expression-language
Usage
To use the functions provided in this package, you need to add the expression_language
key to your plugin configuration
and use the Kiboko\Component\ArrayExpressionLanguage\ArrayExpressionLanguageProvider
Provider.
expression_language:
- Kiboko\Component\ArrayExpressionLanguage\ArrayExpressionLanguageProvider
To determine that a value in your configuration will be a language expression, you must use the @
annotation.
foo: '@=map(input["attributes"], extractData("[fr_FR][data]"))'
List of available functions
Generic functions
firstKey( array input ) : int|string|null
Gets the first key of an arraylastKey( array input ) : int|string|null
Gets the last key of an arraykeyExists( string|int key, array input ) : bool
Checks if the given key or index exists in the arraymerge( array|list ...inputs ) : array
Merge one or more arrayscount( Countable|array input ) : int
Count all elements in an array, or something in an objectcombine( list<int|string> keys, list<mixed> values ) : array
Creates an array by using one array for keys and another for its valuesiterableToArray( Traversable iterator, bool useKeys = true ) : array
Copy the iterator into an arraymap( callable callback, iterable input ) : iterable
Applies the callback to the elements of the given iterablereduce( closure callback, iterable input ) : string
Iteratively reduce the iterable to a single value using a callback functionlist( int length, mixed $value ) : iterable
Fill an array with values
Closures that can be provided to reduce
join( string separator ) : closure
Join array elements with a string
Closures that can be provided to map
extraxctData( string path ) : closure
Retrieves the value of a key in an array or the property of an object