Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

fix(WhoopsError): ensure the SCRIPT_NAME is set before attempting to use it #489

Merged
merged 2 commits into from
Oct 9, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(WhoopsError): ensure the SCRIPT_NAME is set before attempting to …
…use it
  • Loading branch information
gsdevme authored May 26, 2017
commit d03901dde645e7f9039ad3a19af6d1b8c9ee4b99
9 changes: 8 additions & 1 deletion src/Middleware/WhoopsErrorResponseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,18 @@ private function prepareWhoopsHandler(ServerRequestInterface $request, PrettyPag
{
$uri = $request->getAttribute('originalUri', false) ?: $request->getUri();
$request = $request->getAttribute('originalRequest', false) ?: $request;

$serverParams = $request->getServerParams();
$scriptName = '';

if (isset($serverParams['SCRIPT_NAME'])) {
$scriptName = $serverParams['SCRIPT_NAME'];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be cleaned up to:

$serverParams = $request->getServerParams();
$scriptName = (isset($serverParams['SCRIPT_NAME'])) ? $serverParams['SCRIPT_NAME'] : '';

It'll be nice when ZE is pinned to PHP 7.1 and we can use null coalesce operators...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always found it bizarre that people think this is "cleaner". I didn't realise I had written really unwieldily code here. I guess the above is also using a ternary operator so it does at least make it consistent.


$handler->addDataTable('Expressive Application Request', [
'HTTP Method' => $request->getMethod(),
'URI' => (string) $uri,
'Script' => $request->getServerParams()['SCRIPT_NAME'],
'Script' => $scriptName,
'Headers' => $request->getHeaders(),
'Cookies' => $request->getCookieParams(),
'Attributes' => $request->getAttributes(),
Expand Down