Skip to content

Commit d848222

Browse files
authored
Makes the PDO wrapper transparent (php-debugbar#407)
* Making PDO wrapper transparent * Fix check for instance type before enveloping PDO
1 parent 2a71666 commit d848222

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

docs/base_collectors.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,12 @@ Display exceptions
6464

6565
## PDO
6666

67-
Logs SQL queries. You need to wrap your `PDO` object into a `DebugBar\DataCollector\PDO\TraceablePDO` object.
67+
Logs SQL queries.
6868

69-
$pdo = new DebugBar\DataCollector\PDO\TraceablePDO(new PDO('sqlite::memory:'));
7069
$debugbar->addCollector(new DebugBar\DataCollector\PDO\PDOCollector($pdo));
7170

7271
You can even log queries from multiple `PDO` connections:
7372

74-
$pdoRead = new DebugBar\DataCollector\PDO\TraceablePDO(new PDO('sqlite::memory:'));
75-
$pdoWrite = new DebugBar\DataCollector\PDO\TraceablePDO(new PDO('sqlite::memory:'));
76-
7773
$pdoCollector = new DebugBar\DataCollector\PDO\PDOCollector();
7874
$pdoCollector->addConnection($pdoRead, 'read-db');
7975
$pdoCollector->addConnection($pdoWrite, 'write-db');

src/DebugBar/DataCollector/PDO/PDOCollector.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class PDOCollector extends DataCollector implements Renderable, AssetProvider
2121
protected $sqlQuotationChar = '<>';
2222

2323
/**
24-
* @param TraceablePDO $pdo
24+
* @param \PDO $pdo
2525
* @param TimeDataCollector $timeCollector
2626
*/
27-
public function __construct(TraceablePDO $pdo = null, TimeDataCollector $timeCollector = null)
27+
public function __construct(\PDO $pdo = null, TimeDataCollector $timeCollector = null)
2828
{
2929
$this->timeCollector = $timeCollector;
3030
if ($pdo !== null) {
@@ -65,11 +65,14 @@ public function getSqlQuotationChar()
6565
* @param TraceablePDO $pdo
6666
* @param string $name Optional connection name
6767
*/
68-
public function addConnection(TraceablePDO $pdo, $name = null)
68+
public function addConnection(\PDO $pdo, $name = null)
6969
{
7070
if ($name === null) {
7171
$name = spl_object_hash($pdo);
7272
}
73+
if (!($pdo instanceof TraceablePDO)) {
74+
$pdo = new TraceablePDO($pdo);
75+
}
7376
$this->connections[$name] = $pdo;
7477
}
7578

0 commit comments

Comments
 (0)