Download the PHP package xakepehok/expression-executor without Composer
On this page you can find all versions of the php package xakepehok/expression-executor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xakepehok/expression-executor
More information about xakepehok/expression-executor
Files in xakepehok/expression-executor
Package expression-executor
Short Description Expression executor, which allow to implement domain-specific language
License BSD-3-Clause
Informations about the package expression-executor
ExpressionExecutor 
Expression executor, which allows to implement domain-specific language. This lib doesn’t contain any implemented operators or functions. Its only a framework, which allows you to build your own domain-specific language for expressions, with any functions, operators and typing system.
You can define your own operator, functions and variables. For example, you want to calc/execute expressions like:
In example above
MIN
andNUMBER_OF_DAY
- functions{{VARIABLE}}
- variablePI
- syntax user-defined constant (for example, you can define TRUE, FALSE and NULL constants)+
and*
- operators"5"
,"10"
,"2019"
- strings in double-quotes5
,10.5
,(-2)
,2.5
,2
- int/float as is, but negative values should be wrapped in brackets
Also, it support arrays and boolean logic like:
where
["HELLO", "WORLD"]
- array of strings[2+2, 3+3, 5+5, "string here"]
- mixed array of integers and stringsIN
- operator, that check is array contain value or not&&
- logic operator "and"
Installation:
Usage
In order to calc/execute expressions above you need to define those functions, operators and values
MIN():
NUMBER_OF_DAY():
+
operator:
*
operator:
IN
operator:
&&
operator:
Create executor instance:
Features
- Its safe. No
eval()
- Executor can return and work with any types of data. All types checking and manipulating should be implemented in your classes (functions and operators)
- String arguments support escaped double quotes, for example
"My name is \"Timur\""
- Functions accept any count of arguments (you can limit in function body by exceptions)
- Functions arguments can be named
NUMBER_OF_DAY(year: "2019", month: "01", day: "20")
and unnamed NUMBER_OF_DAY("2019", "01", "20"), but not combined - Function arguments can be strings, numbers, variables, constants, other functions result and any expressions
- You can pass context (any common data as array) as second param for
execute()
method. Context will be passed to functions, operators and variables callable - Use brackets
(2 + 2) * 2
for priority - Use brackets for negative numbers, such as
(-1)
,(-1.2)
- You can implement any operator, such as
>
,>=
,<
,<=
and any what you want and desire
See ExecutorTest.php for more examples.
Differences from analogues
- https://symfony.com/doc/current/components/expression_language.html - great symfony component for expressions, but it is impossible to override logic of any built-in operators and also impossible use your own strict type system. Only one way to extend - define your own function
- https://github.com/NeonXP/MathExecutor - good math expressions calculator with user-defined operators and functions, but it is also impossible to use your own strict type system. For example, you can't do something like Datetime - Datetime (with type saving)
All versions of expression-executor with dependencies
ext-mbstring Version *