diff options
author | Bruce Wells <brucekwells@gmail.com> | 2022-04-26 23:14:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 23:14:59 +0300 |
commit | c396a882ffa5f7467947a6a19c2435a7b4cbad22 (patch) | |
tree | e055b512472eb689b0f20d85653de1020b9dafee /README.md | |
parent | ef82911187771e56c8987af5bf03d331cc533fde (diff) |
Prep for V2.2.0 release (#99)V2.2.0
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -9,6 +9,7 @@ * Conditional If logic * Support for user defined operators * Support for user defined functions +* Support for math on user defined objects * Dynamic variable resolution (delayed computation) * Unlimited variable name lengths * String support, as function parameters or as evaluated as a number by PHP @@ -138,6 +139,21 @@ $executor->setVar('var1', 0.15)->setVar('var2', 0.22); echo $executor->execute("$var1 + var2"); ``` +By default, variables must be scalar values (int, float, bool or string). If you would like to support another type, use **setVarValidationHandler** + +```php +$executor->setVarValidationHandler(function (string $name, $variable) { + // allow all scalars and null + if (is_scalar($variable) || $variable === null) { + return; + } + // Allow variables of type DateTime, but not others + if (! $variable instanceof \DateTime) { + throw new MathExecutorException("Invalid variable type"); + } +}); +``` + You can dynamically define variables at run time. If a variable has a high computation cost, but might not be used, then you can define an undefined variable handler. It will only get called when the variable is used, rather than having to always set it initially. ```php |