Vendor lock
This commit is contained in:
116
vendor/zeuxisoo/slim-whoops/src/Zeuxisoo/Whoops/Slim/WhoopsGuard.php
vendored
Normal file
116
vendor/zeuxisoo/slim-whoops/src/Zeuxisoo/Whoops/Slim/WhoopsGuard.php
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Zeuxisoo\Whoops\Slim;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Slim\App as SlimApp;
|
||||
use Whoops\Run as WhoopsRun;
|
||||
use Whoops\Util\Misc;
|
||||
use Whoops\Handler\PrettyPageHandler;
|
||||
use Whoops\Handler\JsonResponseHandler;
|
||||
|
||||
class WhoopsGuard {
|
||||
|
||||
protected $settings = [];
|
||||
protected $request = null;
|
||||
protected $handlers = [];
|
||||
|
||||
/**
|
||||
* Instance the whoops guard object
|
||||
*
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct($settings = []) {
|
||||
$this->settings = array_merge([
|
||||
'enable' => true,
|
||||
'editor' => '',
|
||||
'title' => '',
|
||||
], $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the server request object
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return void
|
||||
*/
|
||||
public function setRequest(ServerRequestInterface $request): void {
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the custom handlers for whoops
|
||||
*
|
||||
* @param array $handlers
|
||||
* @return void
|
||||
*/
|
||||
public function setHandlers(array $handlers): void {
|
||||
$this->handlers = $handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the whoops guard object
|
||||
*
|
||||
* @return WhoopsRun|null
|
||||
*/
|
||||
public function install(): ?WhoopsRun {
|
||||
if ($this->settings['enable'] === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Enable PrettyPageHandler with editor options
|
||||
$prettyPageHandler = new PrettyPageHandler();
|
||||
|
||||
if (empty($this->settings['editor']) === false) {
|
||||
$prettyPageHandler->setEditor($this->settings['editor']);
|
||||
}
|
||||
|
||||
if (empty($this->settings['title']) === false) {
|
||||
$prettyPageHandler->setPageTitle($this->settings['title']);
|
||||
}
|
||||
|
||||
// Add more information to the PrettyPageHandler
|
||||
$contentCharset = '<none>';
|
||||
if (
|
||||
method_exists($this->request, 'getContentCharset') === true &&
|
||||
$this->request->getContentCharset() !== null
|
||||
) {
|
||||
$contentCharset = $this->request->getContentCharset();
|
||||
}
|
||||
|
||||
$prettyPageHandler->addDataTable('Slim Application', [
|
||||
'Version' => SlimApp::VERSION,
|
||||
'Accept Charset' => $this->request->getHeader('ACCEPT_CHARSET') ?: '<none>',
|
||||
'Content Charset' => $contentCharset,
|
||||
'HTTP Method' => $this->request->getMethod(),
|
||||
'Path' => $this->request->getUri()->getPath(),
|
||||
'Query String' => $this->request->getUri()->getQuery() ?: '<none>',
|
||||
'Base URL' => (string) $this->request->getUri(),
|
||||
'Scheme' => $this->request->getUri()->getScheme(),
|
||||
'Port' => $this->request->getUri()->getPort(),
|
||||
'Host' => $this->request->getUri()->getHost(),
|
||||
]);
|
||||
|
||||
// Set Whoops to default exception handler
|
||||
$whoops = new \Whoops\Run;
|
||||
$whoops->pushHandler($prettyPageHandler);
|
||||
|
||||
// Enable JsonResponseHandler when request is AJAX
|
||||
if (Misc::isAjaxRequest() === true){
|
||||
$whoops->pushHandler(new JsonResponseHandler());
|
||||
}
|
||||
|
||||
// Add each custom handler to whoops handler stack
|
||||
if (empty($this->handlers) === false) {
|
||||
foreach($this->handlers as $handler) {
|
||||
$whoops->pushHandler($handler);
|
||||
}
|
||||
}
|
||||
|
||||
$whoops->register();
|
||||
|
||||
return $whoops;
|
||||
}
|
||||
|
||||
}
|
43
vendor/zeuxisoo/slim-whoops/src/Zeuxisoo/Whoops/Slim/WhoopsMiddleware.php
vendored
Normal file
43
vendor/zeuxisoo/slim-whoops/src/Zeuxisoo/Whoops/Slim/WhoopsMiddleware.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Zeuxisoo\Whoops\Slim;
|
||||
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class WhoopsMiddleware implements MiddlewareInterface {
|
||||
|
||||
protected $settings = [];
|
||||
protected $handlers = [];
|
||||
|
||||
/**
|
||||
* Instance the whoops middleware object
|
||||
*
|
||||
* @param array $settings
|
||||
* @param array $handlers
|
||||
*/
|
||||
public function __construct(array $settings = [], array $handlers = []) {
|
||||
$this->settings = $settings;
|
||||
$this->handlers = $handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the requests
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
|
||||
$whoopsGuard = new WhoopsGuard($this->settings);
|
||||
$whoopsGuard->setRequest($request);
|
||||
$whoopsGuard->setHandlers($this->handlers);
|
||||
$whoopsGuard->install();
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user