Version Date Notes By
1.0 2023-06-20 Initial release ROB

Introduction

Variable calc is a reimplementation of the StringCalc used in processes module except this system can handle integer, floats and booleans as well as strings. The architecture similar to StringCalc but it does not support sub calculations yet for example 1 + 2 is a sub calculation of 3 + (1 + 2) as denoted by the brackets.

For now the variable calc allows for the selection of 2 variables and a symbol or function and returns the result of that operation. It is used internally by the WeFlow™ scripting system in the arithmetic and logic components to get the results of those components.

Folder / class structure

|--\ VariableCalc
    |--\ Functions
        |--- Between
        |--- NotBetween
    |--\ Operations
        |--- AndOperator
        |--- ArithPower
        |--- Concatenation
        |--- Differs
        |--- Division
        |--- Equals
        |--- GreaterThan
        |--- GreaterThanOrEqual
        |--- LesserThan
        |--- LesserThanOrEqual
        |--- Modulus
        |--- Multiplication
        |--- OrOperator
        |--- Subtraction
        |--- Sum
    |--- AbstractFunction
    |--- AbstractOperator
    |--- AbstractSymbol
    |--- Variable
    |--- VariableCalc
    |--- VariableCalcOperation

The primary point of interaction with this system is the VariableCalc class. Instance this class where needed and then call the newOperation() function. This will instance a new VariableCalcOperation function, that acts as a container for a single operation (two variables + an operator, this is temporary and will be improved in the future when sub calculations are implemented).

$result = (new VariableCalc())->newOperation()
    ->addVariable($var1)
    ->addVariable($var2)
    ->setOperator($operator)
    ->execute();

Internally, when executing the variables will be passed to the operator/function that corresponds to the symbol in the operator ("+" is replaced with "Sum" class for example) and the operate() function will be called with the variables as operands returning the result of the operation.