-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: #9 support ThinkOrm(just pdo based)
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace WebmanTech\Debugbar\DataCollector; | ||
|
||
use DebugBar\DataCollector\PDO\PDOCollector; | ||
use DebugBar\DataCollector\PDO\TraceablePDO; | ||
use DebugBar\DataCollector\TimeDataCollector; | ||
use think\db\PDOConnection; | ||
use think\facade\Db; | ||
|
||
class ThinkPdoCollector extends PDOCollector | ||
{ | ||
public function __construct(array $thinkOrmConfig = [], TimeDataCollector $timeCollector = null) | ||
{ | ||
$config = array_merge([ | ||
'default' => '', | ||
'connections' => [], | ||
], $thinkOrmConfig); | ||
|
||
$connectionNames = array_keys($config['connections']); | ||
$connectionNames[] = $config['default'] ?? ''; | ||
$connectionNames = array_unique($connectionNames); | ||
|
||
foreach ($connectionNames as $name) { | ||
$connection = Db::connect($name); | ||
if ($connection instanceof PDOConnection) { | ||
$pdo = $connection->connect(); | ||
$this->addConnection(new TraceablePDO($pdo), $name); | ||
} | ||
} | ||
|
||
parent::__construct(null, $timeCollector); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getName() | ||
{ | ||
return 'ThinkDB'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getWidgets() | ||
{ | ||
$name = $this->getName(); | ||
return array( | ||
$name => array( | ||
"icon" => "database", | ||
"widget" => "PhpDebugBar.Widgets.SQLQueriesWidget", | ||
"map" => $name, | ||
"default" => "[]" | ||
), | ||
"{$name}:badge" => array( | ||
"map" => "{$name}.nb_statements", | ||
"default" => 0 | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters