]> BookStack Code Mirror - bookstack/blob - app/Exceptions/WhoopsBookStackPrettyHandler.php
Merge branch 'master' of https://github.com/theodor-franke/BookStack into theodor...
[bookstack] / app / Exceptions / WhoopsBookStackPrettyHandler.php
1 <?php
2
3 namespace BookStack\Exceptions;
4
5 use Whoops\Handler\Handler;
6
7 class WhoopsBookStackPrettyHandler extends Handler
8 {
9     /**
10      * @return int|null A handler may return nothing, or a Handler::HANDLE_* constant
11      */
12     public function handle()
13     {
14         $exception = $this->getException();
15
16         echo view('errors.debug', [
17             'error'       => $exception->getMessage(),
18             'errorClass'  => get_class($exception),
19             'trace'       => $exception->getTraceAsString(),
20             'environment' => $this->getEnvironment(),
21         ])->render();
22
23         return Handler::QUIT;
24     }
25
26     protected function safeReturn(callable $callback, $default = null)
27     {
28         try {
29             return $callback();
30         } catch (\Exception $e) {
31             return $default;
32         }
33     }
34
35     protected function getEnvironment(): array
36     {
37         return [
38             'PHP Version'       => phpversion(),
39             'BookStack Version' => $this->safeReturn(function () {
40                 $versionFile = base_path('version');
41
42                 return trim(file_get_contents($versionFile));
43             }, 'unknown'),
44             'Theme Configured' => $this->safeReturn(function () {
45                 return config('view.theme');
46             }) ?? 'None',
47         ];
48     }
49 }