Reverted errorHandler setter to a method.
This commit is contained in:
parent
fcfa275706
commit
6fec3889a6
2 changed files with 22 additions and 17 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.2503.72020
|
0.2503.72025
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
namespace Index\Http\Routing;
|
namespace Index\Http\Routing;
|
||||||
|
|
||||||
use Stringable;
|
use Stringable;
|
||||||
|
use InvalidArgumentException;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
use Index\Bencode\{Bencode,BencodeSerializable};
|
use Index\Bencode\{Bencode,BencodeSerializable};
|
||||||
use Index\Http\{HttpRequest,HttpStream};
|
use Index\Http\{HttpRequest,HttpStream};
|
||||||
|
@ -37,14 +38,14 @@ class Router implements RequestHandlerInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $charSet Default character set to specify when none is present.
|
* @param string $charSet Default character set to specify when none is present.
|
||||||
* @param ErrorHandler|string $errorHandler Error handling to use for error responses with an empty body. 'html' for the default HTML implementation, 'plain' for the plaintext implementation.
|
* @param ErrorHandler|'html'|'plain' $errorHandler Error handling to use for error responses with an empty body. 'html' for the default HTML implementation, 'plain' for the plaintext implementation.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $charSet = '',
|
string $charSet = '',
|
||||||
ErrorHandler|string $errorHandler = 'html'
|
ErrorHandler|string $errorHandler = 'html'
|
||||||
) {
|
) {
|
||||||
$this->charSetValue = $charSet;
|
$this->charSetValue = $charSet;
|
||||||
$this->errorHandler = $errorHandler;
|
$this->setErrorHandler($errorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,33 +69,37 @@ class Router implements RequestHandlerInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error handler instance.
|
* Error handler instance.
|
||||||
*
|
|
||||||
* @var ErrorHandler
|
|
||||||
*/
|
*/
|
||||||
public ErrorHandler $errorHandler {
|
public ErrorHandler $errorHandler;
|
||||||
get => $this->errorHandler;
|
|
||||||
set(ErrorHandler|string $handler) {
|
/**
|
||||||
if($handler instanceof ErrorHandler)
|
* Sets an error handler.
|
||||||
$this->errorHandler = $handler;
|
*
|
||||||
elseif($handler === 'html')
|
* @param ErrorHandler|'html'|'plain' $handler
|
||||||
$this->setHtmlErrorHandler();
|
*/
|
||||||
else // plain
|
public function setErrorHandler(ErrorHandler|string $handler): void {
|
||||||
$this->setPlainErrorHandler();
|
if($handler instanceof ErrorHandler)
|
||||||
}
|
$this->errorHandler = $handler;
|
||||||
|
elseif($handler === 'html')
|
||||||
|
$this->errorHandler = new HtmlErrorHandler;
|
||||||
|
elseif($handler === 'plain')
|
||||||
|
$this->errorHandler = new PlainErrorHandler;
|
||||||
|
else
|
||||||
|
throw new InvalidArgumentException('$handler must be an instance of ErrorHandler or "html" or "plain"');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the error handler to the basic HTML one.
|
* Set the error handler to the basic HTML one.
|
||||||
*/
|
*/
|
||||||
public function setHtmlErrorHandler(): void {
|
public function setHtmlErrorHandler(): void {
|
||||||
$this->errorHandler = new HtmlErrorHandler;
|
$this->setErrorHandler('html');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the error handler to the plain text one.
|
* Set the error handler to the plain text one.
|
||||||
*/
|
*/
|
||||||
public function setPlainErrorHandler(): void {
|
public function setPlainErrorHandler(): void {
|
||||||
$this->errorHandler = new PlainErrorHandler;
|
$this->setErrorHandler('plain');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue