protected function getContextArray(\Exception $exception = null) { if ($exception) { try { $this->saveException($exception); } catch (IOException $e) { // } } $loggedOnUser = (bool) $this->app['users']->getCurrentUser() ?: false; $showLoggedOff = (bool) $this->app['config']->get('general/debug_show_loggedoff', false); // Grab a section of the file that threw the exception, so we can show it. $filePath = $exception ? $exception->getFile() : null; $lineNumber = $exception ? $exception->getLine() : null; if ($filePath && $lineNumber) { $phpFile = file($filePath) ?: []; $snippet = implode('', array_slice($phpFile, max(0, $lineNumber - 6), 11)); } else { $snippet = false; } // We might or might not have $this->app['request'] yet, which is used in the // template to show the request variables. Use it, or grab what we can get. $request = $this->app['request_stack']->getCurrentRequest() ?: Request::createFromGlobals(); return ['debug' => $this->app['debug'] && ($loggedOnUser || $showLoggedOff), 'request' => $request, 'exception' => ['object' => $exception, 'class_name' => $exception ? (new \ReflectionClass($exception))->getShortName() : null, 'class_fqn' => $exception ? get_class($exception) : null, 'file_path' => $filePath, 'file_name' => basename($filePath), 'trace' => $exception ? $this->getSafeTrace($exception) : null, 'snippet' => $snippet]]; }