diff --git a/composer.json b/composer.json index 62430df..c063b5e 100644 --- a/composer.json +++ b/composer.json @@ -12,5 +12,7 @@ "email": "grumpydeveloper@contentnation.net" } ], - "require": {} + "require": { + "arokettu/arithmetic-parser": "*" + } } diff --git a/scriptedbrowser/commands/base.php b/scriptedbrowser/commands/base.php index 9501969..1f28468 100644 --- a/scriptedbrowser/commands/base.php +++ b/scriptedbrowser/commands/base.php @@ -7,6 +7,28 @@ **/ namespace ScriptedBrowser\Commands; +/** + * calculate given formula + * + * @param \ScriptedBrowser\Main $main main instance + * @param \ScriptedBrowser\Control $control control interface + * @param array $options options + * @return bool always true + */ +function calc($main, $control, $options) +{ + require_once 'vendor/autoload.php'; + $input = $main->vars($options['parameter']); + $result = $options['result']; + try { + $calc = \Arokettu\ArithmeticParser\Calculator::evaluate($input); + $main->setVar($result, $calc); + return true; + } catch (\Exception) { + return false; + } +} + /** * inject and execute given javascript *