Class MathExecutor
- package NXP
| Methods |
| public __clone() |
| public __construct() Base math operators |
| public addFunction(string $name, ?callable $function = NULL) : NXP Add function to executor
|
| public addOperator(NXP Add operator to executor |
| public clearCache() : NXP Clear token's cache |
| public execute(string $expression, bool $cache = true) Execute expression
|
| public getCache() : array Get cache array with tokens
|
| public getFunctions() : array Get all registered functions
|
| public getOperators() : array Get all registered operators to executor
|
| public getVar(string $variable) : ?mixed Get a specific var
|
| public getVars() : array Get all vars
|
| public removeOperator(string $operator) : NXP Remove a specific operator |
| public removeVar(string $variable) : NXP Remove variable from executor |
| public removeVars() : NXP Remove all variables and the variable not found handler |
| public setDivisionByZeroIsZero() : NXP Set division by zero returns zero instead of throwing DivisionByZeroException |
| public setVar(string $variable, ?mixed $value) : NXP Add variable to executor. To set a custom validator use setVarValidationHandler.
|
| public setVarNotFoundHandler(callable $handler) : NXP Define a method that will be invoked when a variable is not found. The first parameter will be the variable name, and the returned value will be used as the variable value. |
| public setVars(array $variables, bool $clear = true) : NXP Add variables to executor
|
| public setVarValidationHandler(?callable $handler) : NXP Define a validation method that will be invoked when a variable is set using setVar. The first parameter will be the variable name, and the second will be the variable value. Set to null to disable validation.
|
| public useBCMath(int $scale = 2) : NXP |
| public varExists(string $variable) : bool Test to see if a variable exists |
| Properties |
protected array $cache = []
|
protected array $functions = []
|
protected $onVarNotFound = NULL
|
protected $onVarValidation = NULL
|
protected array $operators = []
|
| protected array $variables = [] Available variables
|
| Methods |
| protected addDefaults() : NXP Set default operands and functions
|
| protected defaultFunctions() : array Gets the default functions as an array. Key is function name and value is the function as a closure.
|
| protected defaultOperators() : array Get the default operators
|
| protected defaultVars() : array Returns the default variables names as key/value pairs
|
| protected defaultVarValidation(string $variable, ?mixed $value) : void Default variable validation, ensures that the value is a scalar or array.
|