]> BookStack Code Mirror - bookstack/blob - app/Exceptions/BookStackExceptionHandlerPage.php
78f586ad0c98d0f930a5c7f78882dbcfcdf5f614
[bookstack] / app / Exceptions / BookStackExceptionHandlerPage.php
1 <?php
2
3 namespace BookStack\Exceptions;
4
5 use Illuminate\Contracts\Foundation\ExceptionRenderer;
6
7 class BookStackExceptionHandlerPage implements ExceptionRenderer
8 {
9     public function render($throwable)
10     {
11         return view('errors.debug', [
12             'error'       => $throwable->getMessage(),
13             'errorClass'  => get_class($throwable),
14             'trace'       => $throwable->getTraceAsString(),
15             'environment' => $this->getEnvironment(),
16         ])->render();
17     }
18
19     protected function safeReturn(callable $callback, $default = null)
20     {
21         try {
22             return $callback();
23         } catch (\Exception $e) {
24             return $default;
25         }
26     }
27
28     protected function getEnvironment(): array
29     {
30         return [
31             'PHP Version'       => phpversion(),
32             'BookStack Version' => $this->safeReturn(function () {
33                 $versionFile = base_path('version');
34
35                 return trim(file_get_contents($versionFile));
36             }, 'unknown'),
37             'Theme Configured' => $this->safeReturn(function () {
38                 return config('view.theme');
39             }) ?? 'None',
40         ];
41     }
42 }