|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Blitz PHP framework. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2022 Dimitri Sitchet Tomkeu <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace BlitzPHP\Debug; |
|
13
|
|
|
|
|
14
|
|
|
use BlitzPHP\Container\Services; |
|
15
|
|
|
use Spatie\Ignition\Ignition; |
|
|
|
|
|
|
16
|
|
|
use Throwable; |
|
17
|
|
|
use Whoops\Exception\Inspector; |
|
|
|
|
|
|
18
|
|
|
use Whoops\Handler\Handler; |
|
|
|
|
|
|
19
|
|
|
use Whoops\Handler\JsonResponseHandler; |
|
|
|
|
|
|
20
|
|
|
use Whoops\Handler\PlainTextHandler; |
|
|
|
|
|
|
21
|
|
|
use Whoops\Handler\PrettyPageHandler; |
|
|
|
|
|
|
22
|
|
|
use Whoops\Run; |
|
|
|
|
|
|
23
|
|
|
use Whoops\RunInterface; |
|
|
|
|
|
|
24
|
|
|
use Whoops\Util\Misc; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Capture et affiche les erreurs et exceptions via whoops |
|
28
|
|
|
* |
|
29
|
|
|
* Necessite l'instalation de `flip/whoops` ou `spatie/ignition` |
|
30
|
|
|
*/ |
|
31
|
|
|
class Debugger |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Demarre le processus |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function init() |
|
39
|
|
|
{ |
|
40
|
|
|
if (class_exists(Run::class)) { |
|
41
|
|
|
return self::initWhoops(); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
if (class_exists(Ignition::class)) { |
|
44
|
|
|
return self::initIgnition(); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Initialisation du debugger a travers filp/Whoops |
|
50
|
|
|
*/ |
|
51
|
|
|
private static function initWhoops() |
|
52
|
|
|
{ |
|
53
|
|
|
$debugger = new Run(); |
|
54
|
|
|
|
|
55
|
|
|
if (! is_online()) { |
|
56
|
|
|
if (Misc::isCommandLine()) { |
|
57
|
|
|
$debugger->pushHandler(new PlainTextHandler()); |
|
58
|
|
|
} elseif (Misc::isAjaxRequest()) { |
|
59
|
|
|
$debugger->pushHandler(new JsonResponseHandler()); |
|
60
|
|
|
} else { |
|
61
|
|
|
$debugger->pushHandler(new PrettyPageHandler()); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* On log toutes les erreurs |
|
67
|
|
|
*/ |
|
68
|
|
|
$debugger->pushHandler(static function (Throwable $exception, Inspector $inspector, RunInterface $run) { |
|
|
|
|
|
|
69
|
|
|
Services::logger()->error($exception); |
|
70
|
|
|
|
|
71
|
|
|
return Handler::DONE; |
|
72
|
|
|
}); |
|
73
|
|
|
|
|
74
|
|
|
$debugger->register(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Initialisation du debugger a travers spatie/ignition |
|
79
|
|
|
* |
|
80
|
|
|
* @todo customisation du debugger et log des erreurs |
|
81
|
|
|
*/ |
|
82
|
|
|
private static function initIgnition() |
|
83
|
|
|
{ |
|
84
|
|
|
$debugger = Ignition::make(); |
|
85
|
|
|
|
|
86
|
|
|
$debugger->applicationPath(ROOTPATH) |
|
87
|
|
|
->shouldDisplayException(! on_prod()) |
|
88
|
|
|
->register(); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths