mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
Added group attribute to stop router from merging exception-handlers (issue: #573)
- Added new mergeExceptionHandlers attribute to stop router from merging exception-handlers. - RouteGroup: Added setMergeExceptionHandlers and getMergeExceptionHandlers methods. - IRouteGroup: Added setMergeExceptionHandlers and getMergeExceptionHandlers method. - Updated documentation to reflect changes. - Added unit-tests.
This commit is contained in:
@@ -12,6 +12,7 @@ class RouteGroup extends Route implements IGroupRoute
|
||||
protected $name;
|
||||
protected $domains = [];
|
||||
protected $exceptionHandlers = [];
|
||||
protected $mergeExceptionHandlers = true;
|
||||
|
||||
/**
|
||||
* Method called to check if a domain matches
|
||||
@@ -36,6 +37,7 @@ class RouteGroup extends Route implements IGroupRoute
|
||||
|
||||
if ($parameters !== null && count($parameters) !== 0) {
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -174,6 +176,29 @@ class RouteGroup extends Route implements IGroupRoute
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* When enabled group will overwrite any existing exception-handlers.
|
||||
*
|
||||
* @param bool $merge
|
||||
* @return static
|
||||
*/
|
||||
public function setMergeExceptionHandlers(bool $merge): self
|
||||
{
|
||||
$this->mergeExceptionHandlers = $merge;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if group should overwrite existing exception-handlers.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getMergeExceptionHandlers(): bool
|
||||
{
|
||||
return $this->mergeExceptionHandlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge with information from another route.
|
||||
*
|
||||
@@ -187,6 +212,10 @@ class RouteGroup extends Route implements IGroupRoute
|
||||
$this->setPrefix($settings['prefix'] . $this->prefix);
|
||||
}
|
||||
|
||||
if (isset($settings['mergeExceptionHandlers']) === true) {
|
||||
$this->setMergeExceptionHandlers($settings['mergeExceptionHandlers']);
|
||||
}
|
||||
|
||||
if ($merge === false && isset($settings['exceptionHandler']) === true) {
|
||||
$this->setExceptionHandlers((array)$settings['exceptionHandler']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user