Skip to content

Commit

Permalink
Use config for handle_vardumper, move handler, bypass dd(), close #75
Browse files Browse the repository at this point in the history
  • Loading branch information
vpietri committed Apr 3, 2024
1 parent 566b4fd commit a0b2927
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
18 changes: 11 additions & 7 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
{
Expand All @@ -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) {

Expand All @@ -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);
Expand All @@ -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 {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@
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;
}

/**
* @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(...));
}
}

/**
Expand All @@ -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);
}

}
}
6 changes: 3 additions & 3 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
type="ADM\QuickDevBar\Plugin\Framework\App\Cache" sortOrder="1" />
</type>

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


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

0 comments on commit a0b2927

Please sign in to comment.