class ExpressionLanguage

Allows to compile and evaluate expressions written in your own DSL.

Methods

__construct(ParserCacheInterface $cache = null, array $providers = array())

No description

string
compile(Expression|string $expression, array $names = array())

Compiles an expression source code.

string
evaluate(Expression|string $expression, array $values = array())

Evaluate an expression.

parse(Expression|string $expression, array $names)

Parses an expression.

register(string $name, callable $compiler, callable $evaluator)

Registers a function.

addFunction(ExpressionFunction $function)

No description

Details

at line line 35
__construct(ParserCacheInterface $cache = null, array $providers = array())

Parameters

ParserCacheInterface $cache
array $providers

at line line 52
string compile(Expression|string $expression, array $names = array())

Compiles an expression source code.

Parameters

Expression|string $expression The expression to compile
array $names An array of valid names

Return Value

string The compiled PHP source code

at line line 65
string evaluate(Expression|string $expression, array $values = array())

Evaluate an expression.

Parameters

Expression|string $expression The expression to compile
array $values An array of values

Return Value

string The result of the evaluation of the expression

at line line 78
ParsedExpression parse(Expression|string $expression, array $names)

Parses an expression.

Parameters

Expression|string $expression The expression to parse
array $names An array of valid names

Return Value

ParsedExpression A ParsedExpression instance

at line line 114
register(string $name, callable $compiler, callable $evaluator)

Registers a function.

Parameters

string $name The function name
callable $compiler A callable able to compile the function
callable $evaluator A callable able to evaluate the function

Exceptions

LogicException when registering a function after calling evaluate(), compile() or parse()

See also

ExpressionFunction

at line line 123
addFunction(ExpressionFunction $function)

Parameters

ExpressionFunction $function

at line line 128
registerProvider(ExpressionFunctionProviderInterface $provider)