Skip to content

Commit

Permalink
Release Prep (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
phpfui authored May 16, 2022
1 parent 5d6b4a5 commit ddf9dbf
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
});
```

Expand Down Expand Up @@ -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
Expand All @@ -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.

0 comments on commit ddf9dbf

Please sign in to comment.