Skip to content

Commit a0b2927

Browse files
committed
Use config for handle_vardumper, move handler, bypass dd(), close #75
1 parent 566b4fd commit a0b2927

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

Helper/Data.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public function getIdeList()
7676

7777
public function getIdeRegex()
7878
{
79-
if($ide = $this->getConfig('dev/quickdevbar/ide')) {
80-
if (strtolower($ide) == 'custom' && $ideCustom = $this->getConfig('dev/quickdevbar/ide_custom')) {
79+
if($ide = $this->getQdbConfig('ide')) {
80+
if (strtolower($ide) == 'custom' && $ideCustom = $this->getQdbConfig('ide_custom')) {
8181
return $ideCustom;
8282
}
8383

@@ -91,6 +91,10 @@ public function getCacheFrontendPool()
9191
return $this->cacheFrontendPool;
9292
}
9393

94+
public function getQdbConfig($key, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
95+
{
96+
return $this->getConfig('dev/quickdevbar/'.$key, $scopeType, $scopeCode);
97+
}
9498

9599
public function getConfig($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
96100
{
@@ -99,13 +103,13 @@ public function getConfig($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_D
99103

100104
public function defaultAppearance()
101105
{
102-
return $this->getConfig('dev/quickdevbar/appearance');
106+
return $this->getQdbConfig('appearance');
103107
}
104108

105109
public function isToolbarAccessAllowed($testWithRestriction=false)
106110
{
107111
$allow = false;
108-
$enable = $this->getConfig('dev/quickdevbar/enable');
112+
$enable = $this->getQdbConfig('enable');
109113

110114
if ($enable || $testWithRestriction) {
111115

@@ -125,7 +129,7 @@ public function isToolbarAccessAllowed($testWithRestriction=false)
125129

126130
public function isToolbarAreaAllowed($area)
127131
{
128-
$areaEnabled = $this->getConfig('dev/quickdevbar/area');
132+
$areaEnabled = $this->getQdbConfig('area');
129133

130134
return ($areaEnabled == \Magento\Framework\App\Area::AREA_GLOBAL)
131135
|| ($area == $areaEnabled);
@@ -145,7 +149,7 @@ public function isIpAuthorized()
145149

146150
public function getAllowedIps($separator = false)
147151
{
148-
$allowedIps = $this->getConfig('dev/quickdevbar/allow_ips');
152+
$allowedIps = $this->getQdbConfig('allow_ips');
149153
if($allowedIps) {
150154
$allowedIps = preg_split('#\s*,\s*#', $allowedIps, -1, PREG_SPLIT_NO_EMPTY);
151155
} else {
@@ -165,7 +169,7 @@ public function getClientIp()
165169

166170
public function isUserAgentAuthorized()
167171
{
168-
$toolbarHeader = $this->getConfig('dev/quickdevbar/toolbar_header');
172+
$toolbarHeader = $this->getQdbConfig('toolbar_header');
169173

170174
return !empty($toolbarHeader) ? preg_match('/' . preg_quote($toolbarHeader, '/') . '/', $this->getUserAgent()) : false;
171175
}

Plugin/Framework/App/Http.php renamed to Plugin/Framework/App/FrontController.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,32 @@
77
use Symfony\Component\VarDumper\Cloner\VarCloner;
88

99

10-
class Http
10+
class FrontController
1111
{
12-
private \ADM\QuickDevBar\Service\Dumper $dumper;
12+
private $qdbHelper;
13+
14+
private $dumper;
1315

1416
/**
1517
* @param \ADM\QuickDevBar\Service\Dumper $dumper
1618
*/
17-
public function __construct(\ADM\QuickDevBar\Service\Dumper $dumper)
19+
public function __construct(\ADM\QuickDevBar\Helper\Data $qdbHelper,
20+
\ADM\QuickDevBar\Service\Dumper $dumper
21+
)
1822
{
23+
$this->qdbHelper = $qdbHelper;
1924
$this->dumper = $dumper;
2025
}
2126

2227
/**
2328
* @param \Magento\Framework\AppInterface $subject
2429
* @return void
2530
*/
26-
public function beforeLaunch(\Magento\Framework\AppInterface $subject)
31+
public function beforeDispatch(\Magento\Framework\App\FrontControllerInterface $subject)
2732
{
28-
VarDumper::setHandler($this->dumperHandler(...));
33+
if($this->qdbHelper->getQdbConfig('handle_vardumper')) {
34+
$prevHandler = VarDumper::setHandler($this->dumperHandler(...));
35+
}
2936
}
3037

3138
/**
@@ -37,12 +44,14 @@ protected function dumperHandler($var)
3744
$cloner = new VarCloner();
3845
$dumper = new HtmlDumper();
3946

40-
// $dumper->setTheme('light');
4147
$dumper->setTheme('dark');
42-
4348
$dumpBt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[2];
44-
$dumpOutput = $dumper->dump($cloner->cloneVar($var), true);
4549

46-
$this->dumper->addDump($dumpOutput, $dumpBt);
50+
$output = $dumpBt['function'] != 'dd';
51+
$dumpOutput = $dumper->dump($cloner->cloneVar($var), $output);
52+
if($output) {
53+
$this->dumper->addDump($dumpOutput, $dumpBt);
54+
}
55+
4756
}
4857
}

etc/di.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
type="ADM\QuickDevBar\Plugin\Framework\App\Cache" sortOrder="1" />
2121
</type>
2222

23-
<type name="Magento\Framework\App\Http">
23+
<!-- Plugin on Magento\Framework\App\Http should be better but to early to access config-->
24+
<type name="Magento\Framework\App\FrontControllerInterface">
2425
<plugin name="qdb-dumper"
25-
type="ADM\QuickDevBar\Plugin\Framework\App\Http" sortOrder="1" />
26+
type="ADM\QuickDevBar\Plugin\Framework\App\FrontController" sortOrder="1" />
2627
</type>
2728

28-
2929
<type name="Magento\PageCache\Model\Cache\Type">
3030
<plugin name="qdb-trace-cache"
3131
type="ADM\QuickDevBar\Plugin\PageCache\FrontController\BuiltinPlugin" sortOrder="1" />

0 commit comments

Comments
 (0)