Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 2.96 KB

README.md

File metadata and controls

64 lines (46 loc) · 2.96 KB

Array Expression Language

This package extends the ExpressionLanguage Symfony component to compile and evaluate arrays and iterables with custom functions.

Quality (PHPStan lvl 4) PHPUnit Infection PHPStan level 5 PHPStan level 6 PHPStan level 7 PHPStan level 8 PHP

Documentation

See full Documentation

Installation

composer require php-etl/array-expression-language

Usage

You can use these expressions in your configuration files as in the following example :

foo: '@=count(input["myArray"])'

List of available functions

Generic functions

  • firstKey(array $array) : int|string|null
  • lastKey(array $array) : int|string|null
  • keyExists(string|int $key, array $array) : bool
  • merge(array ...$arrays) : array
  • count(Countable|array $value) : int
  • combine(array $keys, array $values) : array
  • iterableToArray(Traversable $iterator, bool $use_keys = true) : array
  • map(callable $callback, iterable $source) : iterable
  • reduce(callable $callback, iterable $source) : string
  • list(int $length, mixed $value) : iterable
  • arrayFilter(array $array, ?callable $callback = null) : array
  • mapValues(array $input, iterable $values) : array

Functions that can be used with reduce

  • join(string $separator) : callable

Functions that can be used with map

  • extraxctData(string $path) : callable

Functions that can be used with arrayFilter

Any function can be used with this method as long as it returns true or false.