Skip to content

Commit

Permalink
improve Templates collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Yongcheng Chen committed Nov 1, 2016
1 parent fe09a9d commit 46b732a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 139 deletions.
12 changes: 1 addition & 11 deletions Block/Collector/EventCollector.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,20 @@
namespace Yong\Magento2DebugBar\Block\Collector;

use DebugBar\DataCollector\TimeDataCollector;
use Yong\Magento2DebugBar\Block\ValueExporter;

class EventCollector extends TimeDataCollector
{
/** @var Dispatcher */
protected $events;

/** @var ValueExporter */
protected $exporter;

public function __construct()
{
parent::__construct();
$this->exporter = new ValueExporter();
}

public function addEvent($name, $starttime, $endtime, $data)
{
$params = [];
foreach ($data as $key => $value) {
$params[$key] = $this->exporter->exportValue($value);
}

$this->addMeasure($name, $starttime, $endtime, $params);
$this->addMeasure($name, $starttime, $endtime, $this->getDataFormatter()->formatVar($data));
}

public function collect()
Expand Down
48 changes: 15 additions & 33 deletions Block/Collector/TemplateCollector.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@
*/
namespace Yong\Magento2DebugBar\Block\Collector;

use DebugBar\DataCollector\TimeDataCollector;
use DebugBar\Bridge\Twig\TwigCollector;
use Yong\Magento2DebugBar\Block\ValueExporter;
use DebugBar\DataCollector\RequestDataCollector;

class TemplateCollector extends TwigCollector {
protected $templates = array();
class TemplateCollector extends RequestDataCollector {
protected $templates = array();
protected $collect_data;

public function __construct($collectData = true)
{
$this->collect_data = $collectData;
$this->name = 'views';
$this->name = 'templates';
$this->templates = array();
$this->exporter = new ValueExporter();
}

/**
Expand All @@ -32,36 +29,21 @@ public function __construct($collectData = true)
*/
public function addView($block, $fileName, $dictionary)
{
$params = array();
foreach ($dictionary as $key => $value) {
$params[$key] = $this->exporter->exportValue($value);
}

$params['block'] = get_class($block);
if ($block instanceof \Magento\Framework\View\Element\AbstractBlock) {
$params['name'] = $block->getNameInLayout();
$params['child'] = implode(';', $block->getChildNames());
$block_name = $block->getNameInLayout();
$dictionary['class'] = get_class($block);
$dictionary['template'] = $fileName;
$dictionary['children'] = $block->getChildNames();
$this->templates[$block_name] = $this->getDataFormatter()->formatVar($dictionary);
}

$this->templates[] = array(
'name' => $fileName,
'param_count' => count($params),
'block' => $params,
'type' => 'php',
);
}

public function collect()
{
$templates = $this->templates;

return array(
'nb_templates' => count($templates),
'templates' => $templates,
);
$this->templates['total_amount'] = count(array_keys($this->templates));
return $this->templates;
}


public function getName()
{
return 'templates';
Expand All @@ -72,14 +54,14 @@ public function getWidgets()
return array(
'templates' => array(
'icon' => 'leaf',
'widget' => 'PhpDebugBar.Widgets.TemplatesWidget',
'widget' => 'PhpDebugBar.Widgets.VariableListWidget',
'map' => 'templates',
'default' => '[]'
),
'templates:badge' => array(
'map' => 'templates.nb_templates',
'default' => 0
)
'map' => 'templates.total_amount',
'default' => 0,
),
);
}
}
95 changes: 0 additions & 95 deletions Block/ValueExporter.php

This file was deleted.

1 change: 1 addition & 0 deletions Framework/Stand.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function InitObjectManagerHijacker(ObjectManagerInterface $objectManager
if ($this->debugbar_enabled && !$this->debugbar_collect_suppressed) {
$this->_objectManager = new ObjectManager($objectManager);
$cache = $this->_objectManager->get('Magento\Framework\App\Cache\StateInterface');
$cache->setEnabled('layout', false);
$cache->setEnabled('full_page', false);
} else {
$this->_objectManager = $objectManager;
Expand Down

0 comments on commit 46b732a

Please sign in to comment.