aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Wells <brucekwells@gmail.com>2019-01-10 21:47:27 +0300
committerGitHub <noreply@github.com>2019-01-10 21:47:27 +0300
commitba505031a329eaf632d1af646308482f9db57b68 (patch)
tree0011b15adaf299ecffb84d5806065c823dadb37b
parent0729b6b9bc0e3cebb868f889e88676b95c121a50 (diff)
Syncing to origin (#4)
* Documentation fixes (#34) Fixing typos in and clarifying documentation. * MathExecutor allow override default operators, functions and vars (#36) * Added simple coc (#37) * Added simple coc * Fix * Replaceable operators (#38) * Updated from NeonXP/MathExecutor * Fixed function in () block issue * Fixing typos in and clarifying documentation. * Syncing from origin (#3) * Documentation fixes (#34) Fixing typos in and clarifying documentation. * MathExecutor allow override default operators, functions and vars (#36) * Allow for operators to be replaced based on regex expression
-rw-r--r--README.md12
-rw-r--r--code-of-conduct.md9
-rw-r--r--src/NXP/Classes/TokenFactory.php3
3 files changed, 22 insertions, 2 deletions
diff --git a/README.md b/README.md
index 39490a4..6579a23 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@ A simple math expressions calculator
* Exceptions on divide by zero, or treat as zero
* Unary Minus (e.g. -3)
* Pi ($pi) and Euler's number ($e) support to 11 decimal places
+* Easily extendable
## Install via Composer:
Stable branch
@@ -152,3 +153,14 @@ Expressions can contain double or single quoted strings that are evaluated the s
```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:
+* defaultOperators
+* defaultFunctions
+* defaultVars
+
+This will allow you to remove functions and operators if needed, or implement different types more simply.
+
+Also note that you can replace an existing default operator by adding a new operator with the same regular expression string. For example if you just need to redefine TokenPlus, you can just add a new operator with the same regex string, in this case '\+'.
+
diff --git a/code-of-conduct.md b/code-of-conduct.md
new file mode 100644
index 0000000..83e0f4e
--- /dev/null
+++ b/code-of-conduct.md
@@ -0,0 +1,9 @@
+# Code of conduct
+
+We don't care who you are IRL. Be professional and responsible.
+
+If you are a good person, we are happy for you.
+
+If you are an asshole to us, we will be assholes in relation to you.
+
+> Do to no one what you yourself dislike \ No newline at end of file
diff --git a/src/NXP/Classes/TokenFactory.php b/src/NXP/Classes/TokenFactory.php
index 4ed55af..778cb59 100644
--- a/src/NXP/Classes/TokenFactory.php
+++ b/src/NXP/Classes/TokenFactory.php
@@ -88,8 +88,7 @@ class TokenFactory
throw new UnknownOperatorException($operatorClass);
}
- $this->operators[] = $operatorClass;
- $this->operators = array_unique($this->operators);
+ $this->operators[$operatorClass::getRegex()] = $operatorClass;
}
/**