- First commit of Negundo
This commit is contained in:
commit
69ed176b1c
18 files changed
+846
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Negundo\Client;
|
||||
|
||||
use Laminas\Diactoros\Response\HtmlResponse;
|
||||
use Psr\Http\Message\ResponseInterface,
|
||||
Psr\Http\Message\ServerRequestInterface,
|
||||
Psr\Http\Server\MiddlewareInterface,
|
||||
Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
class NegundoMiddleware extends Handler implements MiddlewareInterface {
|
||||
|
||||
protected ServerRequestInterface $request;
|
||||
|
||||
public $registerExceptionHandler = false;
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
|
||||
{
|
||||
$this->request = $request;
|
||||
|
||||
try {
|
||||
$response = $handler->handle($request);
|
||||
}
|
||||
catch (\Throwable $ex)
|
||||
{
|
||||
$this->pushData($ex);
|
||||
|
||||
if ( $this->callback ?? false ) {
|
||||
return call_user_func_array($this->callback, [ $ex, $request ] );
|
||||
}
|
||||
else {
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
return $response ?? new HtmlResponse("...");
|
||||
}
|
||||
|
||||
public function handleException(\Throwable $ex) : array
|
||||
{
|
||||
return $this->exceptionHandler->extractExceptionData($ex, $this->request->getServerParams(), $this->request->getParsedBody());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user