PHPackages                             xakepehok/expression-executor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xakepehok/expression-executor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xakepehok/expression-executor
=============================

Expression executor, which allow to implement domain-specific language

0.5.2(1y ago)44.0k↓75%2BSD-3-ClausePHPPHP &gt;=7.4

Since Jan 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/XAKEPEHOK/expression-executor)[ Packagist](https://packagist.org/packages/xakepehok/expression-executor)[ RSS](/packages/xakepehok-expression-executor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (19)Used By (0)

ExpressionExecutor [![Build Status](https://camo.githubusercontent.com/75ef26635a606e26430a511d498bd102cbcfb1a10e542ee94beedc19f313603f/68747470733a2f2f7472617669732d63692e636f6d2f58414b455045484f4b2f65787072657373696f6e2d6578656375746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/XAKEPEHOK/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:

```
MIN(5, 10.5) + NUMBER_OF_DAY(year: "2019", month: "01", day: "20") + PI * {{VARIABLE}} + ((-2) + 2.5) * 2

```

In example above

- `MIN` and `NUMBER_OF_DAY` - functions
- `{{VARIABLE}}` - variable
- `PI` - syntax user-defined constant (for example, you can define TRUE, FALSE and NULL constants)
- `+` and `*` - operators
- `"5"`, `"10"`, `"2019"` - strings in double-quotes
- `5`, `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:

```
("HELLO" IN ["HELLO", "WORLD"]) && (10 IN [2+2, 3+3, 5+5, "string here"])

```

where

- `["HELLO", "WORLD"]` - array of strings
- `[2+2, 3+3, 5+5, "string here"]` - mixed array of integers and strings
- `IN` - operator, that check is array contain value or not
- `&&` - logic operator "and"

### Installation:

[](#installation)

```
composer require xakepehok/expression-executor
```

### Usage

[](#usage)

In order to calc/execute expressions above you need to define those functions, operators and values

MIN():

```
