Framework Update
This commit is contained in:
+2
-1
@@ -17,6 +17,7 @@
|
||||
"illuminate/events": "^8.83",
|
||||
"illuminate/redis": "^8.83",
|
||||
"symfony/finder": "^5.4",
|
||||
"workerman/webman-framework": "^1.4"
|
||||
"workerman/webman-framework": "^1.4",
|
||||
"topthink/think-orm": "^2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,13 @@ class LaravelQuery implements Bootstrap
|
||||
return;
|
||||
}
|
||||
$connections = array_keys(config('database.connections'));
|
||||
if ($default = config('database.default')) {
|
||||
$connections[] = $default;
|
||||
}
|
||||
if (!$connections) {
|
||||
return;
|
||||
}
|
||||
$connections = array_unique($connections);
|
||||
|
||||
$collectorName = (new LaravelQueryCollector())->getName();
|
||||
$debugBar = DebugBar::instance();
|
||||
|
||||
@@ -219,7 +219,7 @@ class LaravelQueryCollector extends QueryCollector
|
||||
|
||||
/**
|
||||
* 由于 event 可能是 Container 下的,则事件会重复绑定
|
||||
* 因此粗腰判断事件的 connection 是否是当前 DB 的
|
||||
* 因此此处判断事件的 connection 是否是当前 DB 的
|
||||
* @param Connection $connection
|
||||
* @param Connection $eventConnection
|
||||
* @return bool
|
||||
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -28,22 +28,21 @@ class DebugBar
|
||||
// 非 request 请求使用一个实例
|
||||
if (!$request) {
|
||||
if (!static::$_instance) {
|
||||
$config = config('plugin.webman-tech.debugbar.app.debugbar', []);
|
||||
static::$_instance = static::createDebugBar($config);
|
||||
static::$_instance = static::createDebugBar();
|
||||
}
|
||||
return static::$_instance;
|
||||
}
|
||||
|
||||
// 每个 request 请求单独创建一个实例
|
||||
if (!$request->{static::REQUEST_KEY}) {
|
||||
$config = config('plugin.webman-tech.debugbar.app.debugbar', []);
|
||||
$request->{static::REQUEST_KEY} = static::createDebugBar($config);
|
||||
$request->{static::REQUEST_KEY} = static::createDebugBar();
|
||||
}
|
||||
return $request->{static::REQUEST_KEY};
|
||||
}
|
||||
|
||||
protected static function createDebugBar(array $config): WebmanDebugBar
|
||||
protected static function createDebugBar(): WebmanDebugBar
|
||||
{
|
||||
$config = config('plugin.webman-tech.debugbar.app.debugbar', []);
|
||||
return new WebmanDebugBar($config);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ div.phpdebugbar-body {
|
||||
div.phpdebugbar-header {
|
||||
min-height: 30px;
|
||||
line-height: 20px;
|
||||
padding-left: 39px;
|
||||
padding-left: 0;
|
||||
text-shadow: 1px 1px #FFF;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace WebmanTech\Debugbar\Storage;
|
||||
|
||||
use DebugBar\Storage\FileStorage;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class AutoCleanFileStorage extends FileStorage
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace WebmanTech\Debugbar\Storage;
|
||||
|
||||
/**
|
||||
* @see https://github.com/maximebf/php-debugbar/pull/527
|
||||
* 后续移除后记得修改 AutoCleanFileStorage 的继承
|
||||
*/
|
||||
class FileStorage extends \DebugBar\Storage\FileStorage
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find(array $filters = array(), $max = 20, $offset = 0)
|
||||
{
|
||||
//Loop through all .json files and remember the modified time and id.
|
||||
$files = array();
|
||||
foreach (new \DirectoryIterator($this->dirname) as $file) {
|
||||
if ($file->getExtension() == 'json') {
|
||||
$files[] = array(
|
||||
'time' => $file->getMTime(),
|
||||
'id' => $file->getBasename('.json')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//Sort the files, newest first
|
||||
usort($files, function ($a, $b) {
|
||||
return $a['time'] < $b['time'] ? 1 : -1;
|
||||
});
|
||||
|
||||
//Load the metadata and filter the results.
|
||||
$results = array();
|
||||
$i = 0;
|
||||
foreach ($files as $file) {
|
||||
//When filter is empty, skip loading the offset
|
||||
if ($i++ < $offset && empty($filters)) {
|
||||
$results[] = null;
|
||||
continue;
|
||||
}
|
||||
$data = $this->get($file['id']);
|
||||
$meta = $data['__meta'];
|
||||
unset($data);
|
||||
if ($this->filter($meta, $filters)) {
|
||||
$results[] = $meta;
|
||||
}
|
||||
if (count($results) >= ($max + $offset)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return array_slice($results, $offset, $max);
|
||||
}
|
||||
}
|
||||
+57
-21
@@ -8,7 +8,7 @@ use DebugBar\DataCollector\ExceptionsCollector;
|
||||
use DebugBar\DataCollector\MessagesCollector;
|
||||
use DebugBar\DebugBar;
|
||||
use DebugBar\OpenHandler;
|
||||
use DebugBar\Storage\FileStorage;
|
||||
use DebugBar\Storage\StorageInterface;
|
||||
use WebmanTech\Debugbar\DataCollector\LaravelQueryCollector;
|
||||
use WebmanTech\Debugbar\DataCollector\LaravelRedisCollector;
|
||||
use WebmanTech\Debugbar\DataCollector\MemoryCollector;
|
||||
@@ -16,12 +16,14 @@ use WebmanTech\Debugbar\DataCollector\PhpInfoCollector;
|
||||
use WebmanTech\Debugbar\DataCollector\RequestDataCollector;
|
||||
use WebmanTech\Debugbar\DataCollector\RouteCollector;
|
||||
use WebmanTech\Debugbar\DataCollector\SessionCollector;
|
||||
use WebmanTech\Debugbar\DataCollector\ThinkPdoCollector;
|
||||
use WebmanTech\Debugbar\DataCollector\TimeDataCollector;
|
||||
use WebmanTech\Debugbar\DataCollector\WebmanCollector;
|
||||
use WebmanTech\Debugbar\Ext\HttpExt;
|
||||
use WebmanTech\Debugbar\Helper\ArrayHelper;
|
||||
use WebmanTech\Debugbar\Helper\StringHelper;
|
||||
use WebmanTech\Debugbar\Storage\AutoCleanFileStorage;
|
||||
use WebmanTech\Debugbar\Storage\FileStorage;
|
||||
use WebmanTech\Debugbar\Traits\DebugBarOverwrite;
|
||||
use support\Container;
|
||||
use Throwable;
|
||||
@@ -41,6 +43,7 @@ class WebmanDebugBar extends DebugBar
|
||||
'storage' => true, // 定义 storage
|
||||
'http_driver' => true, // 定义 http_driver
|
||||
'open_handler_url' => '/_debugbar/open', // storage 启用时打开历史的路由
|
||||
'open_handler_url_make' => null, // 构建用于访问的 open_handler 的 url 地址,callable 类型,用于二级目录访问的场景
|
||||
'asset_base_url' => '/_debugbar/assets', // 静态资源的路由
|
||||
'sample_url' => '/_debugbar/sample', // 示例页面,可用于查看 debugbar 信息,设为 null 关闭
|
||||
'javascript_renderer_options' => [], // 其他 javascriptRenderer 参数
|
||||
@@ -69,6 +72,7 @@ class WebmanDebugBar extends DebugBar
|
||||
'memory' => true,
|
||||
'route' => true,
|
||||
'laravelDB' => true,
|
||||
'thinkDb' => true,
|
||||
'laravelRedis' => true,
|
||||
],
|
||||
'collectors_response' => [
|
||||
@@ -92,6 +96,16 @@ class WebmanDebugBar extends DebugBar
|
||||
$this->config = ArrayHelper::merge($this->config, $config);
|
||||
}
|
||||
|
||||
private static $staticCache = [];
|
||||
|
||||
private function getOrSetStaticCache(string $key, callable $fn)
|
||||
{
|
||||
if (!isset(static::$staticCache[$key])) {
|
||||
static::$staticCache[$key] = $fn();
|
||||
}
|
||||
return static::$staticCache[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
@@ -105,29 +119,36 @@ class WebmanDebugBar extends DebugBar
|
||||
|
||||
// 存储
|
||||
if ($this->config['storage']) {
|
||||
if ($this->config['storage'] === true) {
|
||||
$this->config['storage'] = function () {
|
||||
$path = runtime_path() . '/debugbar';
|
||||
if (class_exists('Symfony\Component\Finder\Finder')) {
|
||||
return new AutoCleanFileStorage($path);
|
||||
}
|
||||
// 使用该存储形式会导致文件数量极多
|
||||
return new FileStorage($path);
|
||||
};
|
||||
}
|
||||
$storage = call_user_func($this->config['storage']);
|
||||
$this->setStorage($storage);
|
||||
$this->setStorage($this->getOrSetStaticCache('storage', function (): StorageInterface {
|
||||
if ($this->config['storage'] === true) {
|
||||
$this->config['storage'] = function () {
|
||||
$path = runtime_path() . '/debugbar';
|
||||
if (class_exists('Symfony\Component\Finder\Finder')) {
|
||||
return new AutoCleanFileStorage($path);
|
||||
}
|
||||
// 使用该存储形式会导致文件数量极多
|
||||
return new FileStorage($path);
|
||||
};
|
||||
}
|
||||
return call_user_func($this->config['storage']);
|
||||
}));
|
||||
}
|
||||
// Collector
|
||||
$collectorMaps = $this->collectorMaps();
|
||||
foreach ($this->config['collectors_boot'] as $name => $builder) {
|
||||
if ($builder === false) {
|
||||
continue;
|
||||
}
|
||||
if ($builder === true && isset($collectorMaps[$name])) {
|
||||
$builder = $collectorMaps[$name];
|
||||
}
|
||||
if ($collector = $this->buildCollector($builder)) {
|
||||
$collector = $this->getOrSetStaticCache('collector_' . $name, function () use ($builder, $name, $collectorMaps) {
|
||||
if ($builder === false) {
|
||||
return null;
|
||||
}
|
||||
if ($builder === true && isset($collectorMaps[$name])) {
|
||||
$builder = $collectorMaps[$name];
|
||||
}
|
||||
if ($collector = $this->buildCollector($builder)) {
|
||||
return $collector;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if ($collector instanceof DataCollectorInterface) {
|
||||
$this->addCollector($collector);
|
||||
}
|
||||
}
|
||||
@@ -182,6 +203,17 @@ class WebmanDebugBar extends DebugBar
|
||||
}
|
||||
return null;
|
||||
},
|
||||
'thinkDb' => function () {
|
||||
if (class_exists('think\facade\Db')) {
|
||||
$timeDataCollector = null;
|
||||
if ($this->hasCollector('time')) {
|
||||
/** @var \DebugBar\DataCollector\TimeDataCollector $timeDataCollector */
|
||||
$timeDataCollector = $this->getCollector('time');
|
||||
}
|
||||
return new ThinkPdoCollector(config('thinkorm', []), $timeDataCollector);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
@@ -224,7 +256,11 @@ class WebmanDebugBar extends DebugBar
|
||||
$renderer = $this->getJavascriptRenderer($this->config['asset_base_url']);
|
||||
// 历史访问
|
||||
if ($this->getStorage() && $this->config['open_handler_url']) {
|
||||
$renderer->setOpenHandlerUrl($this->config['open_handler_url']);
|
||||
$url = $this->config['open_handler_url'];
|
||||
if (is_callable($this->config['open_handler_url_make'])) {
|
||||
$url = call_user_func($this->config['open_handler_url_make'], $url);
|
||||
}
|
||||
$renderer->setOpenHandlerUrl($url);
|
||||
}
|
||||
// 其他配置参数
|
||||
$renderer->setOptions($this->config['javascript_renderer_options']);
|
||||
|
||||
Reference in New Issue
Block a user