|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\DebugBar; |
|
4
|
|
|
|
|
5
|
|
|
use DebugBar\DataCollector\ExceptionsCollector; |
|
6
|
|
|
use DebugBar\DataCollector\MemoryCollector; |
|
7
|
|
|
use DebugBar\DataCollector\MessagesCollector; |
|
8
|
|
|
use DebugBar\DataCollector\PhpInfoCollector; |
|
9
|
|
|
use DebugBar\DataCollector\RequestDataCollector; |
|
10
|
|
|
use DebugBar\DataCollector\TimeDataCollector; |
|
11
|
|
|
use Monolog\Logger as Monolog; |
|
12
|
|
|
use Nip\Database\Connections\Connection; |
|
13
|
|
|
use Nip\Database\DatabaseManager; |
|
14
|
|
|
use Nip\DebugBar\DataCollector\QueryCollector; |
|
15
|
|
|
use Nip\DebugBar\DataCollector\RouteCollector; |
|
16
|
|
|
use Nip\Profiler\Adapters\DebugBar as ProfilerDebugBar; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class StandardDebugBar |
|
20
|
|
|
* @package Nip\DebugBar |
|
21
|
|
|
*/ |
|
22
|
|
|
class StandardDebugBar extends DebugBar |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
public function doBoot() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->addCollector(new PhpInfoCollector()); |
|
28
|
|
|
$this->addCollector(new MessagesCollector()); |
|
29
|
|
|
$this->addCollector(new RequestDataCollector()); |
|
30
|
|
|
$this->addCollector(new TimeDataCollector()); |
|
31
|
|
|
$this->addCollector(new MemoryCollector()); |
|
32
|
|
|
$this->addCollector(new RouteCollector()); |
|
33
|
|
|
|
|
34
|
|
|
if (app()->has('db')) { |
|
35
|
|
|
$this->addQueryCollector(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (app()->has(Monolog::class)) { |
|
39
|
|
|
$monolog = app(Monolog::class); |
|
40
|
|
|
$this->addMonolog($monolog); |
|
41
|
|
|
} else { |
|
42
|
|
|
$this->addCollector(new ExceptionsCollector()); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function addQueryCollector() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->addCollector(new QueryCollector()); |
|
49
|
|
|
|
|
50
|
|
|
$databaseManager = app('db'); |
|
51
|
|
|
$databaseManager->connection(); |
|
52
|
|
|
|
|
53
|
|
|
$this->populateQueryCollector(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function populateQueryCollector() |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var DatabaseManager $databaseManager */ |
|
59
|
|
|
$databaseManager = app('db'); |
|
60
|
|
|
$connections = $databaseManager->getConnections(); |
|
61
|
|
|
|
|
62
|
|
|
foreach ($connections as $connection) { |
|
63
|
|
|
$this->initDatabaseConnection($connection); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param Connection $connection |
|
69
|
|
|
*/ |
|
70
|
|
|
public function initDatabaseConnection($connection) |
|
71
|
|
|
{ |
|
72
|
|
|
$profiler = $connection->getAdapter()->newProfiler()->setEnabled(true); |
|
73
|
|
|
$writer = $profiler->newWriter('DebugBar'); |
|
74
|
|
|
|
|
75
|
|
|
/** @var ProfilerDebugBar $writer */ |
|
76
|
|
|
$writer->setCollector($this->getCollector('queries')); |
|
|
|
|
|
|
77
|
|
|
$profiler->addWriter($writer); |
|
78
|
|
|
$connection->getAdapter()->setProfiler($profiler); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.