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
|
29 |
|
public function __construct(array $settings = []) |
26
|
|
|
{ |
27
|
29 |
|
$this->settings = $settings; |
28
|
29 |
|
$this->whoops = new Run(); |
29
|
29 |
|
$this->whoops->pushHandler($this->createHandler()); |
|
|
|
|
30
|
29 |
|
} |
31
|
|
|
|
32
|
|
|
public function handleError(int $errno, string $errstr, ?string $errfile, ?int $errline) |
33
|
|
|
{ |
34
|
|
|
$level = $this->settings['level']; |
35
|
|
|
$this->whoops->{Run::ERROR_HANDLER}($level, $errstr, $errfile, $errline); |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
public function handleException(\Throwable $exception) |
39
|
|
|
{ |
40
|
1 |
|
$this->whoops->{Run::EXCEPTION_HANDLER}($exception); |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
public function handleShutdown() |
44
|
|
|
{ |
45
|
|
|
$this->whoops->{Run::SHUTDOWN_HANDLER}(); |
46
|
|
|
} |
47
|
|
|
|
48
|
29 |
|
protected function createHandler(): Handler |
49
|
|
|
{ |
50
|
29 |
|
if (PHILE_CLI_MODE) { |
51
|
29 |
|
$handler = new PlainTextHandler; |
52
|
29 |
|
$this->whoops->allowQuit(false); |
53
|
29 |
|
return $handler; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$handler = new PrettyPageHandler; |
57
|
|
|
if (!empty($this->settings['editor'])) { |
58
|
|
|
$handler->setEditor($this->settings['editor']); |
59
|
|
|
} |
60
|
|
|
return $handler; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: