support for calculations
This commit is contained in:
parent
c47142ea5c
commit
f445dcb0be
2 changed files with 25 additions and 1 deletions
|
@ -12,5 +12,7 @@
|
|||
"email": "grumpydeveloper@contentnation.net"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
"require": {
|
||||
"arokettu/arithmetic-parser": "*"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,28 @@
|
|||
**/
|
||||
namespace ScriptedBrowser\Commands;
|
||||
|
||||
/**
|
||||
* calculate given formula
|
||||
*
|
||||
* @param \ScriptedBrowser\Main $main main instance
|
||||
* @param \ScriptedBrowser\Control $control control interface
|
||||
* @param array<string,mixed> $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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue