2021-12-25 22:26:25 -08:00
|
|
|
<?php
|
|
|
|
|
|
2025-02-24 18:44:29 +00:00
|
|
|
use DebugBar\Bridge\NamespacedTwigProfileCollector;
|
2022-01-07 14:45:10 -08:00
|
|
|
use DebugBar\DataCollector\ConfigCollector;
|
2025-02-24 18:44:29 +00:00
|
|
|
use DebugBar\DataCollector\DataCollector;
|
2022-01-07 14:48:48 -08:00
|
|
|
use DebugBar\DataCollector\MemoryCollector;
|
2024-03-09 03:19:55 -08:00
|
|
|
use DebugBar\DataCollector\PDO\PDOCollector;
|
2022-01-07 14:48:48 -08:00
|
|
|
use DebugBar\DataCollector\PhpInfoCollector;
|
2022-01-07 14:45:10 -08:00
|
|
|
use DebugBar\DataCollector\RequestDataCollector;
|
2022-01-07 14:48:48 -08:00
|
|
|
use DebugBar\DataCollector\TimeDataCollector;
|
2021-12-25 22:26:25 -08:00
|
|
|
use DebugBar\DebugBar;
|
2021-12-25 22:31:15 -08:00
|
|
|
use Junker\DebugBar\Bridge\SmartyCollector;
|
2025-02-24 18:44:29 +00:00
|
|
|
use Twig\Environment;
|
|
|
|
|
use Twig\Extension\ProfilerExtension;
|
|
|
|
|
use Twig\Profiler\Profile;
|
2021-12-25 22:26:25 -08:00
|
|
|
|
2022-02-14 20:48:15 -08:00
|
|
|
/**
|
|
|
|
|
* Class to help integrate the PHPDebugBar with NamelessMC.
|
|
|
|
|
*
|
|
|
|
|
* @package NamelessMC\Misc
|
|
|
|
|
* @author Aberdeener
|
2025-02-24 18:44:29 +00:00
|
|
|
* @version 2.2.0
|
2022-02-14 20:48:15 -08:00
|
|
|
* @license MIT
|
|
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
class DebugBarHelper extends Instanceable
|
|
|
|
|
{
|
2022-01-30 19:37:28 -08:00
|
|
|
private ?DebugBar $_debugBar = null;
|
2021-12-25 22:26:25 -08:00
|
|
|
|
|
|
|
|
/**
|
2024-03-09 03:19:55 -08:00
|
|
|
* Enable the PHPDebugBar.
|
2021-12-25 22:26:25 -08:00
|
|
|
*/
|
2025-02-24 18:44:29 +00:00
|
|
|
public function enable(): void
|
2024-03-09 03:19:55 -08:00
|
|
|
{
|
2022-01-07 14:45:10 -08:00
|
|
|
$debugbar = new DebugBar();
|
|
|
|
|
|
2022-01-07 14:48:48 -08:00
|
|
|
$debugbar->addCollector(new TimeDataCollector());
|
2023-03-01 11:35:10 -08:00
|
|
|
|
|
|
|
|
$requestCollector = new RequestDataCollector();
|
|
|
|
|
$requestCollector->useHtmlVarDumper();
|
|
|
|
|
$debugbar->addCollector($requestCollector);
|
|
|
|
|
|
|
|
|
|
$debugbar->addCollector(EventCollector::getInstance());
|
2025-05-02 10:48:26 -07:00
|
|
|
$debugbar->addCollector(CacheCollector::getInstance());
|
2022-01-07 14:45:10 -08:00
|
|
|
|
|
|
|
|
$configCollector = new ConfigCollector();
|
2023-03-01 11:35:10 -08:00
|
|
|
$configCollector->useHtmlVarDumper();
|
2022-06-13 02:21:21 +00:00
|
|
|
$configCollector->setData(array_filter(Config::all(), static function ($key) {
|
2023-03-01 11:35:10 -08:00
|
|
|
return $key !== 'mysql' && $key !== 'email' && $key !== 'authme';
|
2022-01-07 14:45:10 -08:00
|
|
|
}, ARRAY_FILTER_USE_KEY));
|
|
|
|
|
$debugbar->addCollector($configCollector);
|
2021-12-25 22:26:25 -08:00
|
|
|
|
|
|
|
|
$pdoCollector = new PDOCollector(DB::getInstance()->getPDO());
|
2025-04-26 00:29:26 -07:00
|
|
|
$pdoCollector->setRenderSqlWithParams(true, "'");
|
2021-12-25 22:26:25 -08:00
|
|
|
$debugbar->addCollector($pdoCollector);
|
|
|
|
|
|
2022-01-07 14:48:48 -08:00
|
|
|
$debugbar->addCollector(new PhpInfoCollector());
|
|
|
|
|
$debugbar->addCollector(new MemoryCollector());
|
2021-12-25 22:31:15 -08:00
|
|
|
|
2021-12-25 23:02:05 -08:00
|
|
|
$this->_debugBar = $debugbar;
|
2021-12-25 22:26:25 -08:00
|
|
|
}
|
|
|
|
|
|
2025-02-24 18:44:29 +00:00
|
|
|
public function addCollector(DataCollector $collector): void
|
|
|
|
|
{
|
|
|
|
|
$this->_debugBar->addCollector($collector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addSmartyCollector(Smarty $smarty): void
|
|
|
|
|
{
|
|
|
|
|
$smartyCollector = new SmartyCollector($smarty);
|
2025-03-29 14:52:54 +00:00
|
|
|
|
|
|
|
|
if ($this->getDebugBar()->hasCollector($smartyCollector->getName())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-24 18:44:29 +00:00
|
|
|
$smartyCollector->useHtmlVarDumper();
|
|
|
|
|
$this->addCollector($smartyCollector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addTwigCollector(Environment $twig, Profile $profile): void
|
|
|
|
|
{
|
|
|
|
|
$twig->addExtension(new ProfilerExtension($profile));
|
2025-03-29 14:52:54 +00:00
|
|
|
$collector = new NamespacedTwigProfileCollector($profile);
|
|
|
|
|
|
|
|
|
|
if ($this->getDebugBar()->hasCollector($collector->getName())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->addCollector($collector);
|
2025-02-24 18:44:29 +00:00
|
|
|
}
|
|
|
|
|
|
2024-03-09 03:19:55 -08:00
|
|
|
public function getDebugBar(): ?DebugBar
|
|
|
|
|
{
|
2021-12-25 23:02:05 -08:00
|
|
|
return $this->_debugBar;
|
2021-12-25 22:26:25 -08:00
|
|
|
}
|
|
|
|
|
}
|