aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/TokenFactory.php
diff options
context:
space:
mode:
authorBruce Wells <bruce.wells@simparel.com>2018-10-30 23:16:01 +0300
committerBruce Wells <bruce.wells@simparel.com>2018-10-31 16:35:40 +0300
commitf0d4562b9ef3bbc64cb8353f0597e639420ede6b (patch)
tree86f215d0c7187843e863e7a980ae81943e7d4a5f /src/NXP/Classes/TokenFactory.php
parent334dd26e3c78a36002aed34aa26aa526b11c5dfb (diff)
Division By Zero Exception support
Updated the documentation. Unit tests for strings. DivisionByZeroException support.
Diffstat (limited to 'src/NXP/Classes/TokenFactory.php')
-rw-r--r--src/NXP/Classes/TokenFactory.php33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/NXP/Classes/TokenFactory.php b/src/NXP/Classes/TokenFactory.php
index d70dd55..6956f31 100644
--- a/src/NXP/Classes/TokenFactory.php
+++ b/src/NXP/Classes/TokenFactory.php
@@ -35,6 +35,13 @@ class TokenFactory
protected $operators = [];
/**
+ * Divide by zero reporting
+ *
+ * @var bool
+ */
+ protected $divideByZeroReporting = false;
+
+ /**
* Available functions
*
* @var array
@@ -91,6 +98,29 @@ class TokenFactory
}
/**
+ * Set division by zero exception reporting
+ *
+ * @param bool $exception default true
+ *
+ * @return TokenFactory
+ */
+ public function setDivisionByZeroException($exception = true)
+ {
+ $this->divideByZeroReporting = $exception;
+ return $this;
+ }
+
+ /**
+ * Get division by zero exception status
+ *
+ * @return bool
+ */
+ public function getDivisionByZeroException()
+ {
+ return $this->divideByZeroReporting;
+ }
+
+ /**
* @return string
*/
public function getTokenParserRegex()
@@ -143,7 +173,8 @@ class TokenFactory
foreach ($this->operators as $operator) {
$regex = sprintf('/%s/i', $operator::getRegex());
if (preg_match($regex, $token)) {
- return new $operator;
+ $op = new $operator;
+ return $op->setDivisionByZeroException($this->getDivisionByZeroException());
}
}