From f0d4562b9ef3bbc64cb8353f0597e639420ede6b Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Tue, 30 Oct 2018 16:16:01 -0400 Subject: Division By Zero Exception support Updated the documentation. Unit tests for strings. DivisionByZeroException support. --- src/NXP/Classes/TokenFactory.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/NXP/Classes/TokenFactory.php') 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 @@ -34,6 +34,13 @@ class TokenFactory */ protected $operators = []; + /** + * Divide by zero reporting + * + * @var bool + */ + protected $divideByZeroReporting = false; + /** * Available functions * @@ -90,6 +97,29 @@ class TokenFactory return $this->operators; } + /** + * 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 */ @@ -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()); } } -- cgit v1.2.3