profideo-ci / expression-language
Symfony ExpressionLanguage Component
2.10
2018-05-07 08:56 UTC
Requires
- php: >=5.3.9
Requires (Dev)
- symfony/phpunit-bridge: ~2.8|~3.0
- dev-master / 3.0.x-dev
- 2.10
- 2.9
- 2.8.x-dev
- 2.7.x-dev
- v2.7.0-BETA1
- 2.6.x-dev
- v2.6.6
- v2.6.5
- v2.6.4
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.6.0-BETA2
- v2.6.0-BETA1
- 2.5.x-dev
- v2.5.11
- v2.5.10
- v2.5.9
- v2.5.8
- v2.5.7
- v2.5.6
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- v2.5.0-RC1
- v2.5.0-BETA2
- v2.5.0-BETA1
- 2.4.x-dev
- v2.4.10
- v2.4.9
- v2.4.8
- v2.4.7
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.4.0-RC1
- v2.4.0-BETA2
- v2.4.0-BETA1
- dev-test
This package is auto-updated.
Last update: 2024-04-15 01:03:19 UTC
README
The ExpressionLanguage component provides an engine that can compile and evaluate expressions:
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
$language = new ExpressionLanguage();
echo $language->evaluate('1 + foo', array('foo' => 2));
// would output 3
echo $language->compile('1 + foo', array('foo'));
// would output (1 + $foo)
By default, the engine implements simple math and logic functions, method calls, property accesses, and array accesses.
You can extend your DSL with functions:
$compiler = function ($arg) {
return sprintf('strtoupper(%s)', $arg);
};
$evaluator = function (array $variables, $value) {
return strtoupper($value);
};
$language->register('upper', $compiler, $evaluator);
echo $language->evaluate('"foo" ~ upper(foo)', array('foo' => 'bar'));
// would output fooBAR
echo $language->compile('"foo" ~ upper(foo)');
// would output ("foo" . strtoupper($foo))
Resources
You can run the unit tests with the following command:
$ cd path/to/Symfony/Component/ExpressionLanguage/
$ composer.phar install --dev
$ phpunit