-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9162c9
commit 6c5d971
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Illuminate\Foundation\Exceptions; | ||
|
||
use Illuminate\Support\Arr; | ||
use Illuminate\Filesystem\Filesystem; | ||
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 | ||
* @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 | ||
* @return $this | ||
*/ | ||
protected function registerBlacklist($handler) | ||
{ | ||
foreach (config('app.debug_blacklist', []) as $key => $secrets) { | ||
foreach ($secrets as $secret) { | ||
$handler->blacklist($key, $secret); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Register the editor with the handler. | ||
* | ||
* @param \Whoops\Handler\PrettyPageHandler | ||
* @return $this | ||
*/ | ||
protected function registerEditor($handler) | ||
{ | ||
if (config('app.editor', false)) { | ||
$handler->setEditor(config('app.editor')); | ||
} | ||
|
||
return $this; | ||
} | ||
} |