1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://philecms.github.io/ |
4
|
|
|
* @license http://opensource.org/licenses/MIT |
5
|
|
|
* @package Phile\Plugin\Phile\ErrorHandler |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Phile\Plugin\Phile\ErrorHandler; |
9
|
|
|
|
10
|
|
|
use Phile\ServiceLocator\ErrorHandlerInterface; |
11
|
|
|
use Whoops\Handler\Handler; |
12
|
|
|
use Whoops\Handler\PlainTextHandler; |
13
|
|
|
use Whoops\Handler\PrettyPageHandler; |
14
|
|
|
use Whoops\Run; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Developement error handler: use whoops |
18
|
|
|
*/ |
19
|
|
|
class Development implements ErrorHandlerInterface |
20
|
|
|
{ |
21
|
|
|
protected $settings; |
22
|
|
|
|
23
|
|
|
protected $whoops; |
24
|
|
|
|
25
|
34 |
|
public function __construct(array $settings = []) |
26
|
|
|
{ |
27
|
34 |
|
$this->settings = $settings; |
28
|
34 |
|
$this->whoops = new Run(); |
29
|
34 |
|
$this->whoops->pushHandler($this->createHandler()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function handleError( |
33
|
|
|
int $errno, |
34
|
|
|
string $errstr, |
35
|
|
|
?string $errfile, |
36
|
|
|
?int $errline |
37
|
|
|
): bool { |
38
|
|
|
$level = $this->settings['level']; |
39
|
|
|
$this->whoops->{Run::ERROR_HANDLER}($level, $errstr, $errfile, $errline); |
40
|
|
|
|
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
public function handleException(\Throwable $exception) |
45
|
|
|
{ |
46
|
1 |
|
$this->whoops->{Run::EXCEPTION_HANDLER}($exception); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function handleShutdown() |
50
|
|
|
{ |
51
|
|
|
$this->whoops->{Run::SHUTDOWN_HANDLER}(); |
52
|
|
|
} |
53
|
|
|
|
54
|
34 |
|
protected function createHandler(): Handler |
55
|
|
|
{ |
56
|
34 |
|
if (PHILE_CLI_MODE) { |
57
|
34 |
|
$handler = new PlainTextHandler; |
58
|
34 |
|
$this->whoops->allowQuit(false); |
59
|
34 |
|
return $handler; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$handler = new PrettyPageHandler; |
63
|
|
|
if (!empty($this->settings['editor'])) { |
64
|
|
|
$handler->setEditor($this->settings['editor']); |
65
|
|
|
} |
66
|
|
|
return $handler; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|