support for calculations
parent
c47142ea5c
commit
f445dcb0be
|
@ -12,5 +12,7 @@
|
||||||
"email": "grumpydeveloper@contentnation.net"
|
"email": "grumpydeveloper@contentnation.net"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {}
|
"require": {
|
||||||
|
"arokettu/arithmetic-parser": "*"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,28 @@
|
||||||
**/
|
**/
|
||||||
namespace ScriptedBrowser\Commands;
|
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
|
* inject and execute given javascript
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue