-
Notifications
You must be signed in to change notification settings - Fork 21
/
ErrorService.php
50 lines (45 loc) · 1.12 KB
/
ErrorService.php
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
<?php
namespace TypeRocket\Services;
use TypeRocket\Core\Config;
class ErrorService extends Service
{
public const ALIAS = 'tr-error';
public const WHOOPS = 'TypeRocket\Pro\Features\Whoops';
/**
* ErrorService constructor.
*
* @throws \ErrorException
*/
public function __construct()
{
if(
!Config::env('DOING_AJAX', false) &&
Config::get('app.debug') &&
Config::get('app.errors.whoops', true) &&
!isset($_GET['wps_disable']) &&
class_exists(static::WHOOPS)
)
{
$this->whoops();
}
elseif(Config::get('app.errors.throw', true))
{
$this->php();
}
}
/**
* Whoops PHP
*/
protected function whoops() {
$class = static::WHOOPS;
new $class;
}
/**
* @throws \ErrorException
*/
protected function php() {
set_error_handler(function ($num, $str, $file, $line) {
throw new \ErrorException($str, 0, $num, $file, $line);
}, Config::get('app.errors.level', E_ERROR | E_PARSE));
}
}