diff --git a/src/Handler/Logging.php b/src/Handler/Logging.php index c82f09f3..157630f4 100644 --- a/src/Handler/Logging.php +++ b/src/Handler/Logging.php @@ -20,8 +20,6 @@ use Zend\Psr7Bridge\Psr7ServerRequest; use Zend\Stdlib\RequestInterface; -use function ErrorHeroModule\getServerURLandRequestURI; - class Logging { /** @@ -180,16 +178,22 @@ private function collectErrorExceptionData(Throwable $t) : array private function collectErrorExceptionExtraData(array $collectedExceptionData) : array { - if ($this->request instanceof ConsoleRequest) { + $request = $this->request; + if ($request instanceof ConsoleRequest) { $this->serverUrl = \php_uname('n'); $requestUri = ':' . \basename((string) \getcwd()) . ' ' . \get_current_user() - . '$ php ' . $this->request->getScriptName() . ' ' . $this->request->toString(); + . '$ php ' . $request->getScriptName() . ' ' . $request->toString(); } else { - Assertion::isInstanceOf($this->request, HttpRequest::class); - $getServerURLandRequestURI = getServerURLandRequestURI($this->request); - $this->serverUrl = $getServerURLandRequestURI['serverUrl']; - $requestUri = $getServerURLandRequestURI['requestUri']; + Assertion::isInstanceOf($request, HttpRequest::class); + + $uri = $request->getUri(); + $this->serverUrl = $uri->getScheme() . '://' . $uri->getHost(); + $port = $uri->getPort(); + if ($port !== 80) { + $this->serverUrl .= ':' . $port; + } + $requestUri = $request->getRequestUri(); } return [ diff --git a/src/HeroFunction.php b/src/HeroFunction.php index bfc9b54f..3218d274 100644 --- a/src/HeroFunction.php +++ b/src/HeroFunction.php @@ -5,27 +5,10 @@ namespace ErrorHeroModule; use Seld\JsonLint\JsonParser; -use Zend\Http\PhpEnvironment\Request; function detectAjaxMessageContentType(string $message) : string { return (new JsonParser())->lint($message) === null ? 'application/problem+json' : ((\strip_tags($message) === $message) ? 'text/plain' : 'text/html'); -} - -function getServerURLandRequestURI(Request $request) : array -{ - $uri = $request->getUri(); - $serverUrl = $uri->getScheme() . '://' . $uri->getHost(); - $port = $uri->getPort(); - if ($port !== 80) { - $serverUrl .= ':' . $port; - } - $requestUri = $request->getRequestUri(); - - return [ - 'serverUrl' => $serverUrl, - 'requestUri' => $requestUri, - ]; } \ No newline at end of file