Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
psa
/
admin
/
plib
/
modules
/
monitoring
/
vendor
/
mezzio
/
mezzio
/
src
/
Middleware
/
File Content:
WhoopsErrorResponseGenerator.php
<?php declare (strict_types=1); namespace PleskMonitoring\Mezzio\Middleware; use InvalidArgumentException; use PleskMonitoring\Laminas\Stratigility\Utils; use PleskMonitoring\Psr\Http\Message\ResponseInterface; use PleskMonitoring\Psr\Http\Message\ServerRequestInterface; use Throwable; use PleskMonitoring\Webmozart\Assert\Assert; use PleskMonitoring\Whoops\Handler\JsonResponseHandler; use PleskMonitoring\Whoops\Handler\PrettyPageHandler; use PleskMonitoring\Whoops\Run; use PleskMonitoring\Whoops\RunInterface; use function gettype; use function is_object; use function sprintf; class WhoopsErrorResponseGenerator { private RunInterface $whoops; /** * @param RunInterface $whoops * @throws InvalidArgumentException If $whoops is not a Run or RunInterface * instance. */ public function __construct($whoops) { /** @psalm-suppress DocblockTypeContradiction Can be removed with the next major when enforcing argument type */ if (!$whoops instanceof RunInterface) { throw new InvalidArgumentException(sprintf('%s expects a %s or %s instance; received %s', static::class, Run::class, RunInterface::class, is_object($whoops) ? $whoops::class : gettype($whoops))); } $this->whoops = $whoops; } public function __invoke(Throwable $e, ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface { // Walk through all handlers foreach ($this->whoops->getHandlers() as $handler) { // Add fancy data for the PrettyPageHandler if ($handler instanceof PrettyPageHandler) { $this->prepareWhoopsHandler($request, $handler); } // Set Json content type header if ($handler instanceof JsonResponseHandler) { $contentType = $handler->contentType(); $response = $response->withHeader('Content-Type', $contentType); } } $response = $response->withStatus(Utils::getStatusCode($e, $response)); $sendOutputFlag = $this->whoops->writeToOutput(); $this->whoops->writeToOutput(\false); $response->getBody()->write($this->whoops->handleException($e)); $this->whoops->writeToOutput($sendOutputFlag); return $response; } /** * Prepare the Whoops page handler with a table displaying request information */ private function prepareWhoopsHandler(ServerRequestInterface $request, PrettyPageHandler $handler) : void { $uri = $request->getAttribute('originalUri', \false) ?: $request->getUri(); $request = $request->getAttribute('originalRequest', \false) ?: $request; $serverParams = $request->getServerParams(); Assert::isMap($serverParams); $scriptName = $serverParams['SCRIPT_NAME'] ?? ''; $handler->addDataTable('Mezzio Application Request', ['HTTP Method' => $request->getMethod(), 'URI' => (string) $uri, 'Script' => $scriptName, 'Headers' => $request->getHeaders(), 'Cookies' => $request->getCookieParams(), 'Attributes' => $request->getAttributes(), 'Query String Arguments' => $request->getQueryParams(), 'Body Params' => $request->getParsedBody()]); } }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
ErrorResponseGenerator.php
1597 bytes
0644
LazyLoadingMiddleware.php
956 bytes
0644
WhoopsErrorResponseGenerator.php
3223 bytes
0644
N4ST4R_ID | Naxtarrr