mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
Fixed issue with SimpleRouter::error not firing within group (issue: #551).
- Fixed variable incorrect variable reference in `InputItem` class. - Added new `Router::addExceptionHandler` method. - Added parameter types in `Url` class. - Fixed phpdoc parameter-type for `Request::getHeader`.
This commit is contained in:
@@ -97,7 +97,7 @@ class InputItem implements ArrayAccess, IInputItem, IteratorAggregate
|
|||||||
|
|
||||||
public function offsetUnset($offset): void
|
public function offsetUnset($offset): void
|
||||||
{
|
{
|
||||||
unset($this->data[$offset]);
|
unset($this->value[$offset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
|
|||||||
@@ -264,12 +264,12 @@ class Request
|
|||||||
* Get header value by name
|
* Get header value by name
|
||||||
*
|
*
|
||||||
* @param string $name Name of the header.
|
* @param string $name Name of the header.
|
||||||
* @param string|null $defaultValue Value to be returned if header is not found.
|
* @param string|mixed|null $defaultValue Value to be returned if header is not found.
|
||||||
* @param bool $tryParse When enabled the method will try to find the header from both from client (http) and server-side variants, if the header is not found.
|
* @param bool $tryParse When enabled the method will try to find the header from both from client (http) and server-side variants, if the header is not found.
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getHeader(string $name, $defaultValue = null, $tryParse = true): ?string
|
public function getHeader(string $name, $defaultValue = null, bool $tryParse = true): ?string
|
||||||
{
|
{
|
||||||
$name = strtolower($name);
|
$name = strtolower($name);
|
||||||
$header = $this->headers[$name] ?? null;
|
$header = $this->headers[$name] ?? null;
|
||||||
|
|||||||
@@ -431,7 +431,7 @@ class Url implements JsonSerializable
|
|||||||
* @param bool $includeParams
|
* @param bool $includeParams
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getRelativeUrl($includeParams = true): string
|
public function getRelativeUrl(bool $includeParams = true): string
|
||||||
{
|
{
|
||||||
$path = $this->path ?? '/';
|
$path = $this->path ?? '/';
|
||||||
|
|
||||||
@@ -451,7 +451,7 @@ class Url implements JsonSerializable
|
|||||||
* @param bool $includeParams
|
* @param bool $includeParams
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getAbsoluteUrl($includeParams = true): string
|
public function getAbsoluteUrl(bool $includeParams = true): string
|
||||||
{
|
{
|
||||||
$scheme = $this->scheme !== null ? $this->scheme . '://' : '';
|
$scheme = $this->scheme !== null ? $this->scheme . '://' : '';
|
||||||
$host = $this->host ?? '';
|
$host = $this->host ?? '';
|
||||||
|
|||||||
@@ -944,4 +944,10 @@ class Router
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addExceptionHandler(IExceptionHandler $handler): self
|
||||||
|
{
|
||||||
|
$this->exceptionHandlers[] = $handler;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -427,9 +427,7 @@ class SimpleRouter
|
|||||||
{
|
{
|
||||||
$callbackHandler = new CallbackExceptionHandler($callback);
|
$callbackHandler = new CallbackExceptionHandler($callback);
|
||||||
|
|
||||||
static::router()->addRoute(
|
static::router()->addExceptionHandler($callbackHandler);
|
||||||
(new RouteGroup())->addExceptionHandler($callbackHandler)
|
|
||||||
);
|
|
||||||
|
|
||||||
return $callbackHandler;
|
return $callbackHandler;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user