php-etl/array-expression-language

This library implements functions for manipulating array data in ExpressionLanguage

v0.4.2 2023-10-02 15:19 UTC

README

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.