Release Prep (#109)

This commit is contained in:
Bruce Wells 2022-05-16 18:18:37 -04:00 committed by GitHub
parent 5d6b4a5dfd
commit ddf9dbfe0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,8 @@
# A simple and extensible math expressions calculator
## Features:
* Built in support for +, -, *, / and power (^) operators plus ()
* Built in support for +, -, *, / and power (^) operators
* Paratheses () and arrays [] are fully supported
* Logical operators (==, !=, <, <, >=, <=, &&, ||)
* Built in support for most PHP math functions
* Conditional If logic
@ -150,19 +151,18 @@ $executor->setVar('monthly_salaries', [1800, 1900, 1200, 1600]);
echo $executor->execute("avg(monthly_salaries) * min([1.1, 1.3])");
```
By default, variables must be scalar values (int, float, bool or string) or array. If you would like to support another type, use **setVarValidationHandler**
```php
$executor->setVarValidationHandler(function (string $name, $variable) {
// allow all scalars, array and null
if (is_scalar($variable) || is_array($variable) || $variable === null) {
return;
}
// Allow variables of type DateTime, but not others
if (! $variable instanceof \DateTime) {
throw new MathExecutorException("Invalid variable type");
}
// allow all scalars, array and null
if (is_scalar($variable) || is_array($variable) || $variable === null) {
return;
}
// Allow variables of type DateTime, but not others
if (! $variable instanceof \DateTime) {
throw new MathExecutorException("Invalid variable type");
}
});
```
@ -205,14 +205,14 @@ echo $executor->execute('1/0');
```
## String Support:
Expressions can contain double or single quoted strings that are evaluated the same way as PHP evalutes strings as numbers. You can also pass strings to functions.
Expressions can contain double or single quoted strings that are evaluated the same way as PHP evaluates strings as numbers. You can also pass strings to functions.
```php
echo $executor->execute("1 + '2.5' * '.5' + myFunction('category')");
```
## Extending MathExecutor
You can add operators, functions and variables with the public methods in MathExecutor, but if you need to do more serious modifications to base behaviours, the easiest way to extend MathExecutor is to redefine the following methods in your derived class:
You can add operators, functions and variables with the public methods in MathExecutor, but if you need to do more serious modifications to base behaviors, the easiest way to extend MathExecutor is to redefine the following methods in your derived class:
* defaultOperators
* defaultFunctions
* defaultVars
@ -227,4 +227,4 @@ Full class documentation via [PHPFUI/InstaDoc](http://phpfui.com/?n=NXP&c=MathEx
## Future Enhancements
This package will continue to track currently supported versions of PHP.
This package will continue to track currently supported versions of PHP.