1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Provider\Debug; |
13
|
|
|
|
14
|
|
|
use Phalcon\Di\DiInterface; |
15
|
|
|
use Phalcon\Version; |
16
|
|
|
use Zemit\Bootstrap; |
17
|
|
|
use Zemit\Config\ConfigInterface; |
18
|
|
|
use Zemit\Debug; |
19
|
|
|
use Zemit\Provider\AbstractServiceProvider; |
20
|
|
|
use Zemit\Support\Php; |
21
|
|
|
|
22
|
|
|
class ServiceProvider extends AbstractServiceProvider |
23
|
|
|
{ |
24
|
|
|
protected string $serviceName = 'debug'; |
25
|
|
|
|
26
|
|
|
public function register(DiInterface $di): void |
27
|
|
|
{ |
28
|
|
|
$causeCyclicError = $this->causeCyclicError(); |
29
|
|
|
|
30
|
|
|
$di->setShared($this->getName(), function () use ($di, $causeCyclicError) { |
31
|
|
|
|
32
|
|
|
$bootstrap = $di->get('bootstrap'); |
33
|
|
|
assert($bootstrap instanceof Bootstrap); |
34
|
|
|
|
35
|
|
|
$config = $di->get('config'); |
36
|
|
|
assert($config instanceof ConfigInterface); |
37
|
|
|
|
38
|
|
|
$isEnabled = $config->path('app.debug') || $config->path('debug.enable'); |
39
|
|
|
|
40
|
|
|
Php::debug($isEnabled); |
41
|
|
|
$debug = new Debug(); |
42
|
|
|
|
43
|
|
|
if ($isEnabled && !$causeCyclicError && !$bootstrap->isCli()) { |
44
|
|
|
$debugConfig = $config->pathToArray('debug'); |
45
|
|
|
|
46
|
|
|
$debug->listen($debugConfig['exception'] ?? true, $debugConfig['lowSeverity'] ?? false); |
47
|
|
|
$debug->setBlacklist($debugConfig['blacklist'] ?? []); |
48
|
|
|
$debug->setShowFiles($debugConfig['showFiles'] ?? true); |
49
|
|
|
$debug->setShowBackTrace($debugConfig['showBackTrace'] ?? true); |
50
|
|
|
$debug->setShowFileFragment($debugConfig['showFileFragment'] ?? true); |
51
|
|
|
|
52
|
|
|
if (is_string($debugConfig['uri'])) { |
53
|
|
|
$debug->setUri($debugConfig['uri']); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $debug; |
58
|
|
|
}); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function causeCyclicError(): bool |
62
|
|
|
{ |
63
|
|
|
return |
64
|
|
|
version_compare(PHP_VERSION, '8.0.0', '>=') && |
65
|
|
|
version_compare(Version::get(), '5.0.0', '<'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|