Class MathExecutor
- package NXP
Methods |
public __clone () |
public
__construct
() Base math operators |
public
addFunction
(
string
$name
,
?
callable
$function
=
NULL
) :
self
Add function to executor
|
public
addOperator
(
NXP Add operator to executor
|
public
clearCache
() :
self
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
) Get a specific var
|
public
getVars
() :
array
Get all vars
|
public
removeOperator
(
string
$operator
) :
self
Remove a specific operator
|
public
removeVar
(
string
$variable
) :
self
Remove variable from executor
|
public
removeVars
() :
self
Remove all variables and the variable not found handler
|
public
setDivisionByZeroIsZero
() :
self
Set division by zero returns zero instead of throwing DivisionByZeroException |
public
setVar
(
string
$variable
,
$value
) :
self
Add variable to executor. To set a custom validator use setVarValidationHandler.
|
public
setVarNotFoundHandler
(
callable
$handler
) :
self
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
) :
self
Add variables to executor
|
public
setVarValidationHandler
(
?
callable
$handler
) :
self
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.
|
public useBCMath ( int $scale = 2 ) : self |
public
varExists
(
string
$variable
) :
bool
Test to see if a variable exists |
Properties |
protected
array
$cache
|
protected
array
$functions
|
protected
$onVarNotFound
|
protected
$onVarValidation
|
protected
array
$operators
|
protected
array
$variables
Available variables
|
Methods |
protected
addDefaults
() :
self
Set default operands and functions
|
protected
defaultFunctions
() :
array
Gets the default functions as an array. Key is function name
|
protected
defaultOperators
() :
array
Get the default operators
|
protected
defaultVars
() :
array
Returns the default variables names as key/value pairs
|
protected
defaultVarValidation
(
string
$variable
,
$value
) :
void
Default variable validation, ensures that the value is a scalar or array.
|