WhoopsHandler.php
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Illuminate\Foundation\Exceptions;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Whoops\Handler\PrettyPageHandler;
class WhoopsHandler
{
/**
* Create a new Whoops handler for debug mode.
*
* @return \Whoops\Handler\PrettyPageHandler
*/
public function forDebug()
{
return tap(new PrettyPageHandler, function ($handler) {
$handler->handleUnconditionally(true);
$this->registerApplicationPaths($handler)
->registerBlacklist($handler)
->registerEditor($handler);
});
}
/**
* Register the application paths with the handler.
*
* @param \Whoops\Handler\PrettyPageHandler $handler
* @return $this
*/
protected function registerApplicationPaths($handler)
{
$handler->setApplicationPaths(
array_flip($this->directoriesExceptVendor())
);
return $this;
}
/**
* Get the application paths except for the "vendor" directory.
*
* @return array
*/
protected function directoriesExceptVendor()
{
return Arr::except(
array_flip((new Filesystem)->directories(base_path())),
[base_path('vendor')]
);
}
/**
* Register the blacklist with the handler.
*
* @param \Whoops\Handler\PrettyPageHandler $handler
* @return $this
*/
protected function registerBlacklist($handler)
{
foreach (config('app.debug_blacklist', config('app.debug_hide', [])) as $key => $secrets) {
foreach ($secrets as $secret) {
$handler->blacklist($key, $secret);
}
}
return $this;
}
/**
* Register the editor with the handler.
*
* @param \Whoops\Handler\PrettyPageHandler $handler
* @return $this
*/
protected function registerEditor($handler)
{
if (config('app.editor', false)) {
$handler->setEditor(config('app.editor'));
}
return $this;
}
}