From a0b2927b7ac4bba14c59d9d77b9b762404ee76f8 Mon Sep 17 00:00:00 2001 From: Vincent Pietri Date: Wed, 3 Apr 2024 14:23:10 +0200 Subject: [PATCH] Use config for handle_vardumper, move handler, bypass dd(), close #75 --- Helper/Data.php | 18 ++++++++----- .../App/{Http.php => FrontController.php} | 27 ++++++++++++------- etc/di.xml | 6 ++--- 3 files changed, 32 insertions(+), 19 deletions(-) rename Plugin/Framework/App/{Http.php => FrontController.php} (50%) diff --git a/Helper/Data.php b/Helper/Data.php index dc864a9..a025272 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -76,8 +76,8 @@ public function getIdeList() public function getIdeRegex() { - if($ide = $this->getConfig('dev/quickdevbar/ide')) { - if (strtolower($ide) == 'custom' && $ideCustom = $this->getConfig('dev/quickdevbar/ide_custom')) { + if($ide = $this->getQdbConfig('ide')) { + if (strtolower($ide) == 'custom' && $ideCustom = $this->getQdbConfig('ide_custom')) { return $ideCustom; } @@ -91,6 +91,10 @@ public function getCacheFrontendPool() return $this->cacheFrontendPool; } + public function getQdbConfig($key, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null) + { + return $this->getConfig('dev/quickdevbar/'.$key, $scopeType, $scopeCode); + } public function getConfig($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null) { @@ -99,13 +103,13 @@ public function getConfig($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_D public function defaultAppearance() { - return $this->getConfig('dev/quickdevbar/appearance'); + return $this->getQdbConfig('appearance'); } public function isToolbarAccessAllowed($testWithRestriction=false) { $allow = false; - $enable = $this->getConfig('dev/quickdevbar/enable'); + $enable = $this->getQdbConfig('enable'); if ($enable || $testWithRestriction) { @@ -125,7 +129,7 @@ public function isToolbarAccessAllowed($testWithRestriction=false) public function isToolbarAreaAllowed($area) { - $areaEnabled = $this->getConfig('dev/quickdevbar/area'); + $areaEnabled = $this->getQdbConfig('area'); return ($areaEnabled == \Magento\Framework\App\Area::AREA_GLOBAL) || ($area == $areaEnabled); @@ -145,7 +149,7 @@ public function isIpAuthorized() public function getAllowedIps($separator = false) { - $allowedIps = $this->getConfig('dev/quickdevbar/allow_ips'); + $allowedIps = $this->getQdbConfig('allow_ips'); if($allowedIps) { $allowedIps = preg_split('#\s*,\s*#', $allowedIps, -1, PREG_SPLIT_NO_EMPTY); } else { @@ -165,7 +169,7 @@ public function getClientIp() public function isUserAgentAuthorized() { - $toolbarHeader = $this->getConfig('dev/quickdevbar/toolbar_header'); + $toolbarHeader = $this->getQdbConfig('toolbar_header'); return !empty($toolbarHeader) ? preg_match('/' . preg_quote($toolbarHeader, '/') . '/', $this->getUserAgent()) : false; } diff --git a/Plugin/Framework/App/Http.php b/Plugin/Framework/App/FrontController.php similarity index 50% rename from Plugin/Framework/App/Http.php rename to Plugin/Framework/App/FrontController.php index 57281c3..61b2774 100644 --- a/Plugin/Framework/App/Http.php +++ b/Plugin/Framework/App/FrontController.php @@ -7,15 +7,20 @@ use Symfony\Component\VarDumper\Cloner\VarCloner; -class Http +class FrontController { - private \ADM\QuickDevBar\Service\Dumper $dumper; + private $qdbHelper; + + private $dumper; /** * @param \ADM\QuickDevBar\Service\Dumper $dumper */ - public function __construct(\ADM\QuickDevBar\Service\Dumper $dumper) + public function __construct(\ADM\QuickDevBar\Helper\Data $qdbHelper, + \ADM\QuickDevBar\Service\Dumper $dumper + ) { + $this->qdbHelper = $qdbHelper; $this->dumper = $dumper; } @@ -23,9 +28,11 @@ public function __construct(\ADM\QuickDevBar\Service\Dumper $dumper) * @param \Magento\Framework\AppInterface $subject * @return void */ - public function beforeLaunch(\Magento\Framework\AppInterface $subject) + public function beforeDispatch(\Magento\Framework\App\FrontControllerInterface $subject) { - VarDumper::setHandler($this->dumperHandler(...)); + if($this->qdbHelper->getQdbConfig('handle_vardumper')) { + $prevHandler = VarDumper::setHandler($this->dumperHandler(...)); + } } /** @@ -37,12 +44,14 @@ protected function dumperHandler($var) $cloner = new VarCloner(); $dumper = new HtmlDumper(); -// $dumper->setTheme('light'); $dumper->setTheme('dark'); - $dumpBt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[2]; - $dumpOutput = $dumper->dump($cloner->cloneVar($var), true); - $this->dumper->addDump($dumpOutput, $dumpBt); + $output = $dumpBt['function'] != 'dd'; + $dumpOutput = $dumper->dump($cloner->cloneVar($var), $output); + if($output) { + $this->dumper->addDump($dumpOutput, $dumpBt); + } + } } diff --git a/etc/di.xml b/etc/di.xml index c4cd016..115779b 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -20,12 +20,12 @@ type="ADM\QuickDevBar\Plugin\Framework\App\Cache" sortOrder="1" /> - + + + type="ADM\QuickDevBar\Plugin\Framework\App\FrontController" sortOrder="1" /> -