Skip to content

Commit 6c5d971

Browse files
committed
add file
1 parent f9162c9 commit 6c5d971

File tree

1 file changed

+86
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)