Ecocode_Profiler - Version 1.2.0

Version Notes

Download this release

Release Info

Developer Justus Krapp
Extension Ecocode_Profiler
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.1.0 to 1.2.0

Files changed (106) hide show
  1. app/code/community/Ecocode/Profiler/Block/Collector/Base.php +27 -6
  2. app/code/community/Ecocode/Profiler/Block/Collector/Layout/Panel.php +3 -2
  3. app/code/community/Ecocode/Profiler/Block/Collector/Mysql/Panel.php +47 -12
  4. app/code/community/Ecocode/Profiler/Block/Collector/Request/Toolbar.php +18 -0
  5. app/code/community/Ecocode/Profiler/Block/Renderer/AbstractRenderer.php +8 -1
  6. app/code/community/Ecocode/Profiler/Block/Renderer/Bag.php +23 -0
  7. app/code/community/Ecocode/Profiler/Block/Renderer/CallStack.php +43 -0
  8. app/code/community/Ecocode/Profiler/Block/Renderer/Log/LogTable.php +1 -0
  9. app/code/community/Ecocode/Profiler/Block/Renderer/Request/ToolbarHandler.php +19 -0
  10. app/code/community/Ecocode/Profiler/Block/Renderer/Table.php +37 -0
  11. app/code/community/Ecocode/Profiler/Block/Toolbar.php +3 -0
  12. app/code/community/Ecocode/Profiler/Helper/Code.php +1 -1
  13. app/code/community/Ecocode/Profiler/Helper/Data.php +38 -11
  14. app/code/community/Ecocode/Profiler/Helper/Renderer.php +24 -11
  15. app/code/community/Ecocode/Profiler/Helper/Sql.php +6 -6
  16. app/code/community/Ecocode/Profiler/Helper/ValueExporter.php +9 -9
  17. app/code/community/Ecocode/Profiler/Model/AppDev.php +4 -1
  18. app/code/community/Ecocode/Profiler/Model/Collector/AbstractDataCollector.php +28 -10
  19. app/code/community/Ecocode/Profiler/Model/Collector/ConfigDataCollector.php +22 -28
  20. app/code/community/Ecocode/Profiler/Model/Collector/LayoutDataCollector.php +48 -24
  21. app/code/community/Ecocode/Profiler/Model/Collector/ModelDataCollector.php +7 -7
  22. app/code/community/Ecocode/Profiler/Model/Collector/RequestDataCollector.php +190 -49
  23. app/code/community/Ecocode/Profiler/Model/Collector/TranslationDataCollector.php +30 -12
  24. app/code/community/Ecocode/Profiler/Model/Context.php +2 -0
  25. app/code/community/Ecocode/Profiler/Model/Logger.php +4 -4
  26. app/code/community/Ecocode/Profiler/Model/Logger/DebugHandler.php +1 -1
  27. app/code/community/Ecocode/Profiler/Model/Logger/DebugHandlerInterface.php +28 -0
  28. app/code/community/Ecocode/Profiler/Model/LoggerInterface.php +7 -0
  29. app/code/community/Ecocode/Profiler/Model/NullLogger.php +149 -0
  30. app/code/community/Ecocode/Profiler/Model/Observer.php +21 -0
  31. app/code/community/Ecocode/Profiler/Model/Observer/Context.php +20 -0
  32. app/code/community/Ecocode/Profiler/Model/Profile.php +5 -5
  33. app/code/community/Ecocode/Profiler/Model/Profiler.php +6 -0
  34. app/code/community/Ecocode/Profiler/Model/Profiler/FileStorage.php +2 -2
  35. app/code/community/Ecocode/Profiler/Model/Session.php +14 -0
  36. app/code/community/Ecocode/Profiler/Tests/Dev/Controller/AbstractControllerTest.php +0 -70
  37. app/code/community/Ecocode/Profiler/Tests/Dev/DevModeTest.php +0 -33
  38. app/code/community/Ecocode/Profiler/Tests/Dev/Fixtures/DummyCacheBackend.php +0 -7
  39. app/code/community/Ecocode/Profiler/Tests/Dev/Fixtures/ResponseHttp.php +0 -10
  40. app/code/community/Ecocode/Profiler/Tests/Dev/Helper/CodeTest.php +0 -55
  41. app/code/community/Ecocode/Profiler/Tests/Dev/Helper/ContextTest.php +0 -136
  42. app/code/community/Ecocode/Profiler/Tests/Dev/Helper/DataTest.php +0 -94
  43. app/code/community/Ecocode/Profiler/Tests/Dev/Helper/RewriteTest.php +0 -124
  44. app/code/community/Ecocode/Profiler/Tests/Dev/Helper/SqlTest.php +0 -56
  45. app/code/community/Ecocode/Profiler/Tests/Dev/Helper/ValueExporterTest.php +0 -60
  46. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/CacheDataCollectorTest.php +0 -89
  47. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/ConfigCollectorTest.php +0 -51
  48. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/ContextDataCollectorTest.php +0 -54
  49. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/CustomerDataCollectorTest.php +0 -54
  50. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/EventDataCollectorTest.php +0 -68
  51. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/LayoutDataCollectorTest.php +0 -221
  52. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/LogDataCollectorTest.php +0 -84
  53. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/MemoryDataCollectorTest.php +0 -71
  54. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/ModelDataCollectorTest.php +0 -177
  55. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/MysqlDataCollectorTest.php +0 -23
  56. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/RequestDataCollectorTest.php +0 -158
  57. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/RewriteDataCollectorTest.php +0 -39
  58. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/TimeDataCollectorTest.php +0 -30
  59. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/TranslationDataCollectorTest.php +0 -79
  60. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Http/HeaderBagTest.php +0 -192
  61. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Http/ParameterBagTest.php +0 -181
  62. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Http/ResponseHeaderBagTest.php +0 -160
  63. app/code/community/Ecocode/Profiler/Tests/Dev/Model/LoggerTest.php +0 -87
  64. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Observer/ContextTest.php +0 -66
  65. app/code/community/Ecocode/Profiler/Tests/Dev/Model/ObserverTest.php +0 -163
  66. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageCoreModelResourceDbAbstractTest.php +0 -118
  67. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageCoreModelResourceTest.php +0 -29
  68. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageCoreModelTranslateTest.php +0 -66
  69. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageEavModelEntityAbstractTest.php +0 -111
  70. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageTest.php +0 -43
  71. app/code/community/Ecocode/Profiler/Tests/Dev/Model/Profiler/FileStorageTest.php +0 -346
  72. app/code/community/Ecocode/Profiler/Tests/Dev/Model/ProfilerTest.php +0 -58
  73. app/code/community/Ecocode/Profiler/Tests/Dev/bootstrap.php +0 -54
  74. app/code/community/Ecocode/Profiler/Tests/Dev/controllers/CacheControllerTest.php +0 -168
  75. app/code/community/Ecocode/Profiler/Tests/Prod/DevModeTest.php +0 -33
  76. app/code/community/Ecocode/Profiler/Tests/Prod/bootstrap.php +0 -51
  77. app/code/community/Ecocode/Profiler/Tests/TestHelper.php +0 -91
  78. app/code/community/Ecocode/Profiler/autoloader.php +20 -3
  79. app/code/community/Ecocode/Profiler/controllers/IndexController.php +14 -11
  80. app/code/community/Ecocode/Profiler/debug.php +1 -1
  81. app/code/community/Ecocode/Profiler/etc/config.xml +1 -1
  82. app/code/community/Ecocode/Profiler/etc/development.xml +14 -0
  83. app/code/community/Ecocode/Profiler/overwrite/Mage.php +17 -15
  84. app/code/community/Ecocode/Profiler/overwrite/MageCoreModelStore.php +1 -0
  85. app/code/community/Ecocode/Profiler/overwrite/MageCoreModelTranslate.php +7 -6
  86. app/design/frontend/base/default/layout/ecocode_profiler.xml +1 -1
  87. app/design/frontend/base/default/template/ecocode_profiler/collector/cache/toolbar.phtml +4 -4
  88. app/design/frontend/base/default/template/ecocode_profiler/collector/log/panel/log-table.phtml +6 -33
  89. app/design/frontend/base/default/template/ecocode_profiler/collector/model/panel.phtml +2 -2
  90. app/design/frontend/base/default/template/ecocode_profiler/collector/mysql/menu.phtml +7 -6
  91. app/design/frontend/base/default/template/ecocode_profiler/collector/mysql/panel.phtml +15 -21
  92. app/design/frontend/base/default/template/ecocode_profiler/collector/mysql/panel/query-table.phtml +3 -3
  93. app/design/frontend/base/default/template/ecocode_profiler/collector/request/panel.phtml +105 -64
  94. app/design/frontend/base/default/template/ecocode_profiler/collector/request/toolbar.phtml +50 -14
  95. app/design/frontend/base/default/template/ecocode_profiler/collector/request/toolbar/handler.phtml +32 -0
  96. app/design/frontend/base/default/template/ecocode_profiler/collector/translation/panel/table.phtml +13 -17
  97. app/design/frontend/base/default/template/ecocode_profiler/layout.phtml +1 -1
  98. app/design/frontend/base/default/template/ecocode_profiler/profiler/base.css.phtml +1 -1
  99. app/design/frontend/base/default/template/ecocode_profiler/profiler/summery.phtml +97 -73
  100. app/design/frontend/base/default/template/ecocode_profiler/renderer/bag.phtml +34 -0
  101. app/design/frontend/base/default/template/ecocode_profiler/renderer/call-stack.phtml +49 -0
  102. app/design/frontend/base/default/template/ecocode_profiler/renderer/context.phtml +6 -1
  103. app/design/frontend/base/default/template/ecocode_profiler/renderer/table.phtml +23 -0
  104. app/design/frontend/base/default/template/ecocode_profiler/toolbar_js.phtml +1 -0
  105. lib/SqlFormatter.php +1080 -0
  106. package.xml +79 -62
app/code/community/Ecocode/Profiler/Block/Collector/Base.php CHANGED
@@ -12,6 +12,9 @@ class Ecocode_Profiler_Block_Collector_Base
12
  /** @var Ecocode_Profiler_Model_Profile */
13
  protected $profile;
14
 
 
 
 
15
  public function setCollector(Ecocode_Profiler_Model_Collector_DataCollectorInterface $collector)
16
  {
17
  $this->collector = $collector;
@@ -23,6 +26,20 @@ class Ecocode_Profiler_Block_Collector_Base
23
  }
24
 
25
  /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  * @return Ecocode_Profiler_Model_Profile
27
  */
28
  public function getProfile()
@@ -33,13 +50,17 @@ class Ecocode_Profiler_Block_Collector_Base
33
  return $this->profile;
34
  }
35
 
36
- public function renderBag($bag, array $data = [])
 
 
 
 
37
  {
38
- /** @var Ecocode_Profiler_Block_Bag $bagBlock */
39
- $bagBlock = $this->getLayout()->createBlock('ecocode_profiler/bag');
40
- $data['bag'] = $bag;
41
- $bagBlock->setData($data);
42
 
43
- return $bagBlock->toHtml();
44
  }
 
45
  }
12
  /** @var Ecocode_Profiler_Model_Profile */
13
  protected $profile;
14
 
15
+ /** @var Ecocode_Profiler_Helper_Renderer */
16
+ protected $rendererHelper;
17
+
18
  public function setCollector(Ecocode_Profiler_Model_Collector_DataCollectorInterface $collector)
19
  {
20
  $this->collector = $collector;
26
  }
27
 
28
  /**
29
+ * @deprecated
30
+ *
31
+ * @param $bag
32
+ * @param array $data
33
+ * @return mixed
34
+ */
35
+ public function renderBag($bag, array $data = [])
36
+ {
37
+ return $this->getRendererHelper()
38
+ ->renderBag($bag, $data);
39
+ }
40
+
41
+ /**
42
+ * @codeCoverageIgnore
43
  * @return Ecocode_Profiler_Model_Profile
44
  */
45
  public function getProfile()
50
  return $this->profile;
51
  }
52
 
53
+ /**
54
+ * @codeCoverageIgnore
55
+ * @return Ecocode_Profiler_Helper_Renderer
56
+ */
57
+ public function getRendererHelper()
58
  {
59
+ if ($this->rendererHelper === null) {
60
+ $this->rendererHelper = Mage::helper('ecocode_profiler/renderer');
61
+ }
 
62
 
63
+ return $this->rendererHelper;
64
  }
65
+
66
  }
app/code/community/Ecocode/Profiler/Block/Collector/Layout/Panel.php CHANGED
@@ -75,12 +75,13 @@ class Ecocode_Profiler_Block_Collector_Layout_Panel
75
  /** @var Ecocode_Profiler_Model_Collector_LayoutDataCollector $collector */
76
  $collector = $this->getCollector();
77
  $totalRenderTime = $collector->getTotalRenderTime();
78
- $nodeList = $collector->getRenderLog();
 
79
  foreach ($nodeList as $id => &$node) {
80
  $node['render_time_percent'] = $node['render_time_incl'] / $totalRenderTime;
81
  }
 
82
  foreach ($nodeList as $id => &$node) {
83
- $nodeList[$id] = $node;
84
  if ($node['parent_id'] === false) {
85
  $this->resolveChildren($node, $nodeList);
86
  $tree[$id] = $node;
75
  /** @var Ecocode_Profiler_Model_Collector_LayoutDataCollector $collector */
76
  $collector = $this->getCollector();
77
  $totalRenderTime = $collector->getTotalRenderTime();
78
+ $nodeList = $collector->getRenderLog();
79
+
80
  foreach ($nodeList as $id => &$node) {
81
  $node['render_time_percent'] = $node['render_time_incl'] / $totalRenderTime;
82
  }
83
+
84
  foreach ($nodeList as $id => &$node) {
 
85
  if ($node['parent_id'] === false) {
86
  $this->resolveChildren($node, $nodeList);
87
  $tree[$id] = $node;
app/code/community/Ecocode/Profiler/Block/Collector/Mysql/Panel.php CHANGED
@@ -19,7 +19,8 @@ class Ecocode_Profiler_Block_Collector_Mysql_Panel
19
  public function _construct()
20
  {
21
  //ban cache usage as we dont need the cache and it causes some overhead
22
- Mage::app()->getCacheInstance()->banUse(Mage_Core_Block_Abstract::CACHE_GROUP);
 
23
 
24
  $this->setTemplate('ecocode_profiler/collector/mysql/panel.phtml');
25
  parent::_construct();
@@ -48,12 +49,12 @@ class Ecocode_Profiler_Block_Collector_Mysql_Panel
48
  $this->queries[] = $queryData;
49
  }
50
 
51
- usort($this->queriesByContext, function ($a, $b) {
52
- return $b['count'] - $a['count'];
53
  });
54
 
55
- usort($this->identicalQueries, function ($a, $b) {
56
- return $b['count'] - $a['count'];
57
  });
58
 
59
  $this->identicalQueries = array_filter($this->identicalQueries, function ($item) {
@@ -66,10 +67,7 @@ class Ecocode_Profiler_Block_Collector_Mysql_Panel
66
 
67
  protected function processType(array &$queryData)
68
  {
69
- $sql = $queryData['sql'];
70
- $type = explode(' ', $sql, 2);
71
- $type = reset($type);
72
- $type = strtolower($type);
73
 
74
  if (isset($this->queryCountByType[$type])) {
75
  $this->queryCountByType[$type]++;
@@ -78,11 +76,24 @@ class Ecocode_Profiler_Block_Collector_Mysql_Panel
78
  $queryData['type'] = $type;
79
  }
80
 
 
 
 
 
 
 
 
 
 
81
  protected function processIdentical(array $queryData)
82
  {
83
- $queryId = md5($queryData['sql'] . implode(',', $queryData['params']));
 
 
84
 
85
  if (!isset($this->identicalQueries[$queryId])) {
 
 
86
  $this->identicalQueries[$queryId] = [
87
  'id' => $queryId,
88
  'count' => 0,
@@ -92,10 +103,24 @@ class Ecocode_Profiler_Block_Collector_Mysql_Panel
92
  ];
93
  }
94
  $this->identicalQueries[$queryId]['count']++;
95
- $this->identicalQueries[$queryId]['total_time'] += $queryData['time'];
96
- $this->identicalQueries[$queryId]['traces'][] = $queryData['trace'];
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  protected function processContext(array $queryData)
100
  {
101
  $contextKey = $queryData['context'];
@@ -147,6 +172,7 @@ class Ecocode_Profiler_Block_Collector_Mysql_Panel
147
  $this->prepareQueryData();
148
  $this->queryCountByType = array_filter($this->queryCountByType);
149
  }
 
150
  return $this->queryCountByType;
151
  }
152
 
@@ -155,6 +181,7 @@ class Ecocode_Profiler_Block_Collector_Mysql_Panel
155
  if ($this->queriesByContext === null) {
156
  $this->prepareQueryData();
157
  }
 
158
  return $this->queriesByContext;
159
  }
160
 
@@ -180,4 +207,12 @@ class Ecocode_Profiler_Block_Collector_Mysql_Panel
180
  }
181
  return $this->queryTableRenderer;
182
  }
 
 
 
 
 
 
 
 
183
  }
19
  public function _construct()
20
  {
21
  //ban cache usage as we dont need the cache and it causes some overhead
22
+ //only ban it here as we would get some issues on the cache panel
23
+ $this->banBlockCacheUsage();
24
 
25
  $this->setTemplate('ecocode_profiler/collector/mysql/panel.phtml');
26
  parent::_construct();
49
  $this->queries[] = $queryData;
50
  }
51
 
52
+ usort($this->queriesByContext, function ($context1, $context2) {
53
+ return $context2['count'] - $context1['count'];
54
  });
55
 
56
+ usort($this->identicalQueries, function ($query1, $query2) {
57
+ return $query2['count'] - $query1['count'];
58
  });
59
 
60
  $this->identicalQueries = array_filter($this->identicalQueries, function ($item) {
67
 
68
  protected function processType(array &$queryData)
69
  {
70
+ $type = $this->getQueryType($queryData['sql']);
 
 
 
71
 
72
  if (isset($this->queryCountByType[$type])) {
73
  $this->queryCountByType[$type]++;
76
  $queryData['type'] = $type;
77
  }
78
 
79
+ protected function getQueryType($sql)
80
+ {
81
+ $type = explode(' ', $sql, 2);
82
+ $type = reset($type);
83
+ $type = strtolower($type);
84
+
85
+ return $type;
86
+ }
87
+
88
  protected function processIdentical(array $queryData)
89
  {
90
+ $queryId = $this->getQueryId($queryData);
91
+ $time = $queryData['time'];
92
+ $trace = $queryData['trace'];
93
 
94
  if (!isset($this->identicalQueries[$queryId])) {
95
+ //unset query specif data
96
+ unset($queryData['time'], $queryData['trace']);
97
  $this->identicalQueries[$queryId] = [
98
  'id' => $queryId,
99
  'count' => 0,
103
  ];
104
  }
105
  $this->identicalQueries[$queryId]['count']++;
106
+ $this->identicalQueries[$queryId]['total_time'] += $time;
107
+ $this->identicalQueries[$queryId]['traces'][] = $trace;
108
  }
109
 
110
+ /**
111
+ * @param array $queryData
112
+ * @return string
113
+ */
114
+ protected function getQueryId(array $queryData)
115
+ {
116
+ $params = isset($queryData['params']) ? $queryData['params'] : [];
117
+
118
+ return md5($queryData['sql'] . implode(',', $params));
119
+ }
120
+
121
+ /**
122
+ * @param array $queryData
123
+ */
124
  protected function processContext(array $queryData)
125
  {
126
  $contextKey = $queryData['context'];
172
  $this->prepareQueryData();
173
  $this->queryCountByType = array_filter($this->queryCountByType);
174
  }
175
+
176
  return $this->queryCountByType;
177
  }
178
 
181
  if ($this->queriesByContext === null) {
182
  $this->prepareQueryData();
183
  }
184
+
185
  return $this->queriesByContext;
186
  }
187
 
207
  }
208
  return $this->queryTableRenderer;
209
  }
210
+
211
+ /**
212
+ * @codeCoverageIgnore
213
+ */
214
+ protected function banBlockCacheUsage()
215
+ {
216
+ Mage::app()->getCacheInstance()->banUse(Mage_Core_Block_Abstract::CACHE_GROUP);
217
+ }
218
  }
app/code/community/Ecocode/Profiler/Block/Collector/Request/Toolbar.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Ecocode_Profiler_Block_Collector_Request_Toolbar
5
+ */
6
+ class Ecocode_Profiler_Block_Collector_Request_Toolbar
7
+ extends Ecocode_Profiler_Block_Collector_Base
8
+ {
9
+ public function renderHandler($controller, $route = false, $method = false)
10
+ {
11
+ $renderer = $this->getRendererHelper()->getInstance('request_toolbarHandler');
12
+
13
+ return $renderer->render(
14
+ ['controller' => $controller, 'route' => $route, 'method' => $method]
15
+ );
16
+ }
17
+
18
+ }
app/code/community/Ecocode/Profiler/Block/Renderer/AbstractRenderer.php CHANGED
@@ -11,10 +11,17 @@ class Ecocode_Profiler_Block_Renderer_AbstractRenderer
11
  {
12
  protected $_templateFileCache = [];
13
 
 
 
 
 
14
  public function render(array $data = [])
15
  {
16
  $this->setData($data);
17
- return $this->toHtml();
 
 
 
18
  }
19
 
20
  public function getTemplateFile()
11
  {
12
  protected $_templateFileCache = [];
13
 
14
+ /**
15
+ * @param array $data
16
+ * @return string
17
+ */
18
  public function render(array $data = [])
19
  {
20
  $this->setData($data);
21
+ $html = $this->toHtml();
22
+
23
+ $this->unsetData();
24
+ return $html;
25
  }
26
 
27
  public function getTemplateFile()
app/code/community/Ecocode/Profiler/Block/Renderer/Bag.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Ecocode_Profiler_Block_Bag
5
+ *
6
+ * @method getBag
7
+ */
8
+ class Ecocode_Profiler_Block_Renderer_Bag
9
+ extends Ecocode_Profiler_Block_Renderer_AbstractRenderer
10
+ {
11
+ public function _construct()
12
+ {
13
+ $this->setTemplate('ecocode_profiler/renderer/bag.phtml');
14
+ parent::_construct();
15
+ }
16
+
17
+ public function getLabels()
18
+ {
19
+ $labels = $this->getData('labels');
20
+
21
+ return $labels ? $labels : [];
22
+ }
23
+ }
app/code/community/Ecocode/Profiler/Block/Renderer/CallStack.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Ecocode_Profiler_Block_Bag
5
+ *
6
+ * @method getBag
7
+ */
8
+ class Ecocode_Profiler_Block_Renderer_CallStack
9
+ extends Ecocode_Profiler_Block_Renderer_AbstractRenderer
10
+ {
11
+ public function _construct()
12
+ {
13
+ $this->setTemplate('ecocode_profiler/renderer/call-stack.phtml');
14
+ parent::_construct();
15
+ }
16
+
17
+ public function getStackId()
18
+ {
19
+ $id = $this->getData('id');
20
+ if (!$id) {
21
+ $this->setData('id', uniqid());
22
+ }
23
+
24
+ return $id;
25
+ }
26
+
27
+ public function getStack()
28
+ {
29
+ $trace = $this->getData('stack');
30
+ if (!$trace) {
31
+ return [];
32
+ }
33
+
34
+ return $trace;
35
+ }
36
+
37
+ public function shouldWarp()
38
+ {
39
+ $wrap = $this->getData('wrap');
40
+
41
+ return $wrap === null ? true : $wrap;
42
+ }
43
+ }
app/code/community/Ecocode/Profiler/Block/Renderer/Log/LogTable.php CHANGED
@@ -36,6 +36,7 @@ class Ecocode_Profiler_Block_Renderer_Log_LogTable
36
  {
37
  $logs = $this->getLogs();
38
  $log = reset($logs);
 
39
  return isset($log['channel']);
40
  }
41
  }
36
  {
37
  $logs = $this->getLogs();
38
  $log = reset($logs);
39
+
40
  return isset($log['channel']);
41
  }
42
  }
app/code/community/Ecocode/Profiler/Block/Renderer/Request/ToolbarHandler.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Ecocode_Profiler_Block_Renderer_Request_ToolbarHandler
5
+ *
6
+ * @method getMethod
7
+ * @method getRoute
8
+ * @method getController
9
+ */
10
+ class Ecocode_Profiler_Block_Renderer_Request_ToolbarHandler
11
+ extends Ecocode_Profiler_Block_Renderer_AbstractRenderer
12
+ {
13
+ public function _construct()
14
+ {
15
+ $this->setTemplate('ecocode_profiler/collector/request/toolbar/handler.phtml');
16
+ parent::_construct();
17
+ }
18
+ }
19
+
app/code/community/Ecocode/Profiler/Block/Renderer/Table.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Ecocode_Profiler_Block_Renderer_Table
5
+ *
6
+ */
7
+ class Ecocode_Profiler_Block_Renderer_Table
8
+ extends Ecocode_Profiler_Block_Renderer_AbstractRenderer
9
+ {
10
+ public function _construct()
11
+ {
12
+ $this->setTemplate('ecocode_profiler/renderer/table.phtml');
13
+ parent::_construct();
14
+ }
15
+
16
+ public function getClass()
17
+ {
18
+ $class = $this->getData('class');
19
+
20
+ return $class ? $class : '';
21
+ }
22
+
23
+ public function getLabels()
24
+ {
25
+ $labels = $this->getData('labels');
26
+
27
+ return $labels ? $labels : [];
28
+ }
29
+
30
+
31
+ public function getItems()
32
+ {
33
+ $items = $this->getData('items');
34
+
35
+ return $items ? $items : [];
36
+ }
37
+ }
app/code/community/Ecocode/Profiler/Block/Toolbar.php CHANGED
@@ -21,6 +21,7 @@ class Ecocode_Profiler_Block_Toolbar
21
  if ($this->getProfile()) {
22
  return $this->getProfile()->getToken();
23
  }
 
24
  return false;
25
  }
26
 
@@ -30,6 +31,7 @@ class Ecocode_Profiler_Block_Toolbar
30
  $this->collectors = $this->getProfile()->getCollectors();
31
 
32
  }
 
33
  return $this->collectors;
34
  }
35
 
@@ -52,6 +54,7 @@ class Ecocode_Profiler_Block_Toolbar
52
  }
53
 
54
  /**
 
55
  * @return Ecocode_Profiler_Model_Profile
56
  */
57
  public function getProfile()
21
  if ($this->getProfile()) {
22
  return $this->getProfile()->getToken();
23
  }
24
+
25
  return false;
26
  }
27
 
31
  $this->collectors = $this->getProfile()->getCollectors();
32
 
33
  }
34
+
35
  return $this->collectors;
36
  }
37
 
54
  }
55
 
56
  /**
57
+ * @codeCoverageIgnore
58
  * @return Ecocode_Profiler_Model_Profile
59
  */
60
  public function getProfile()
app/code/community/Ecocode/Profiler/Helper/Code.php CHANGED
@@ -148,7 +148,7 @@ class Ecocode_Profiler_Helper_Code
148
  if (false !== $link = $this->getFileLink($file, $line)) {
149
  $flags = ENT_QUOTES | ENT_SUBSTITUTE;
150
 
151
- return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
152
  }
153
 
154
  return $text;
148
  if (false !== $link = $this->getFileLink($file, $line)) {
149
  $flags = ENT_QUOTES | ENT_SUBSTITUTE;
150
 
151
+ return sprintf('<a target="profiler_link_target" href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
152
  }
153
 
154
  return $text;
app/code/community/Ecocode/Profiler/Helper/Data.php CHANGED
@@ -8,13 +8,14 @@ class Ecocode_Profiler_Helper_Data
8
  protected static $version;
9
  protected static $overwriteDirectory;
10
 
11
- protected $configClassNameReflection;
12
  protected $classNameCache;
 
13
 
14
  public static function getOverwriteDir()
15
  {
16
  if (self::$overwriteDirectory === null) {
17
- self::$overwriteDirectory = MAGENTO_ROOT . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
18
  }
19
 
20
  if (!file_exists(self::$overwriteDirectory)) {
@@ -39,7 +40,7 @@ class Ecocode_Profiler_Helper_Data
39
 
40
  if (self::$version === null) {
41
  //try to load it from the config directly
42
- $configFile = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'config.xml';
43
  $xml = file_get_contents($configFile);
44
  preg_match('/<version>([0-9\.]+)<\/version>/', $xml, $matches);
45
  if (!$matches) {
@@ -72,7 +73,9 @@ class Ecocode_Profiler_Helper_Data
72
  file_put_contents($cacheFile, $code);
73
  }
74
 
75
- require_once $cacheFile;
 
 
76
  }
77
 
78
  /**
@@ -81,7 +84,7 @@ class Ecocode_Profiler_Helper_Data
81
  * @param string|object $className
82
  * @return string
83
  */
84
- public function getClassGroup($className)
85
  {
86
  if (is_object($className)) {
87
  $className = get_class($className);
@@ -103,12 +106,12 @@ class Ecocode_Profiler_Helper_Data
103
  if ($this->classNameCache !== null && $reload === false) {
104
  return $this->classNameCache;
105
  }
106
- if ($this->configClassNameReflection === null) {
107
- $this->configClassNameReflection = new ReflectionProperty('Mage_Core_Model_Config', '_classNameCache');
108
- $this->configClassNameReflection->setAccessible(true);
109
  }
110
 
111
- $classNameCache = $this->configClassNameReflection->getValue(Mage::getConfig());
112
  foreach ($classNameCache as $groupRoot) {
113
  foreach ($groupRoot as $module => $classNames) {
114
  foreach ($classNames as $class => $className) {
@@ -155,7 +158,7 @@ class Ecocode_Profiler_Helper_Data
155
  public function cleanBacktrace(array $backtrace, array $ignoreCalls = [], array $ignoreInstanceOf = [])
156
  {
157
  $item = reset($backtrace);
158
- while ($item && $this->_cleanBacktrace($item, $ignoreCalls, $ignoreInstanceOf)) {
159
  array_shift($backtrace);
160
  $item = reset($backtrace);
161
  }
@@ -163,7 +166,7 @@ class Ecocode_Profiler_Helper_Data
163
  return $backtrace;
164
  }
165
 
166
- public function _cleanBacktrace(array $data, array $ignoreCalls = [], array $ignoreInstanceOf = [])
167
  {
168
  //remove if not called from a class
169
  if (!isset($data['class'], $data['function'])) {
@@ -188,4 +191,28 @@ class Ecocode_Profiler_Helper_Data
188
  return false;
189
  }
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  }
8
  protected static $version;
9
  protected static $overwriteDirectory;
10
 
11
+ protected $configClassReflection;
12
  protected $classNameCache;
13
+ protected $profilerSession;
14
 
15
  public static function getOverwriteDir()
16
  {
17
  if (self::$overwriteDirectory === null) {
18
+ self::$overwriteDirectory = join(DIRECTORY_SEPARATOR, [MAGENTO_ROOT, 'var', 'cache', '']);
19
  }
20
 
21
  if (!file_exists(self::$overwriteDirectory)) {
40
 
41
  if (self::$version === null) {
42
  //try to load it from the config directly
43
+ $configFile = join(DIRECTORY_SEPARATOR, [__DIR__, '..', 'etc', 'config.xml']);
44
  $xml = file_get_contents($configFile);
45
  preg_match('/<version>([0-9\.]+)<\/version>/', $xml, $matches);
46
  if (!$matches) {
73
  file_put_contents($cacheFile, $code);
74
  }
75
 
76
+ //register overwrite
77
+ Ecocode_Profiler_Autoloader::getAutoloader()
78
+ ->addToClassMap($className, $cacheFile);
79
  }
80
 
81
  /**
84
  * @param string|object $className
85
  * @return string
86
  */
87
+ public function resolveClassGroup($className)
88
  {
89
  if (is_object($className)) {
90
  $className = get_class($className);
106
  if ($this->classNameCache !== null && $reload === false) {
107
  return $this->classNameCache;
108
  }
109
+ if ($this->configClassReflection === null) {
110
+ $this->configClassReflection = new ReflectionProperty('Mage_Core_Model_Config', '_classNameCache');
111
+ $this->configClassReflection->setAccessible(true);
112
  }
113
 
114
+ $classNameCache = $this->configClassReflection->getValue(Mage::getConfig());
115
  foreach ($classNameCache as $groupRoot) {
116
  foreach ($groupRoot as $module => $classNames) {
117
  foreach ($classNames as $class => $className) {
158
  public function cleanBacktrace(array $backtrace, array $ignoreCalls = [], array $ignoreInstanceOf = [])
159
  {
160
  $item = reset($backtrace);
161
+ while ($item && $this->shouldRemoveBacktraceItem($item, $ignoreCalls, $ignoreInstanceOf)) {
162
  array_shift($backtrace);
163
  $item = reset($backtrace);
164
  }
166
  return $backtrace;
167
  }
168
 
169
+ protected function shouldRemoveBacktraceItem(array $data, array $ignoreCalls = [], array $ignoreInstanceOf = [])
170
  {
171
  //remove if not called from a class
172
  if (!isset($data['class'], $data['function'])) {
191
  return false;
192
  }
193
 
194
+ public function getTokenFromResponse(Mage_Core_Controller_Response_Http $response)
195
+ {
196
+ $token = null;
197
+ foreach ($response->getHeaders() as $header) {
198
+ if ($header['name'] === 'X-Debug-Token') {
199
+ $token = $header['value'];
200
+ break;
201
+ }
202
+ }
203
+ return $token;
204
+ }
205
+
206
+ /**
207
+ * @codeCoverageIgnore
208
+ * @return Ecocode_Profiler_Model_Session
209
+ */
210
+ public function getSession()
211
+ {
212
+ if ($this->profilerSession === null) {
213
+ $this->profilerSession = Mage::getSingleton('ecocode_profiler/session');
214
+ }
215
+
216
+ return $this->profilerSession;
217
+ }
218
  }
app/code/community/Ecocode/Profiler/Helper/Renderer.php CHANGED
@@ -6,29 +6,42 @@
6
  class Ecocode_Profiler_Helper_Renderer
7
  extends Mage_Core_Helper_Abstract
8
  {
9
- protected $backTraceRenderer;
10
 
11
- public function get($name)
12
  {
 
13
 
 
 
14
  }
15
 
 
 
 
 
 
16
 
17
- public function renderBackTrace($id, $trace)
18
  {
19
- return $this->getBackTraceRenderer()
20
- ->setData(['id' => $id, 'trace' => $trace])
21
- ->toHtml();
22
  }
23
 
24
  /**
25
- * @return Ecocode_Profiler_Block_Renderer_BackTrace
 
26
  */
27
- public function getBackTraceRenderer()
28
  {
29
- if ($this->backTraceRenderer === null) {
30
- $this->backTraceRenderer = Mage::app()->getLayout()->createBlock('ecocode_profiler/renderer_backTrace');
31
  }
32
- return $this->backTraceRenderer;
 
 
 
 
 
33
  }
34
  }
6
  class Ecocode_Profiler_Helper_Renderer
7
  extends Mage_Core_Helper_Abstract
8
  {
9
+ protected $renderer = [];
10
 
11
+ public function renderBag($bag, array $data = [])
12
  {
13
+ $data['bag'] = $bag;
14
 
15
+ return $this->getInstance('bag')
16
+ ->render($data);
17
  }
18
 
19
+ public function renderTable($data, $labels = null)
20
+ {
21
+ return $this->getInstance('table')
22
+ ->render(['items' => $data, 'labels' => $labels]);
23
+ }
24
 
25
+ public function renderCallStack($id, $stack, $wrap = true)
26
  {
27
+ return $this->getInstance('callStack')
28
+ ->render(['id' => $id, 'stack' => $stack, 'wrap' => $wrap]);
 
29
  }
30
 
31
  /**
32
+ * @param $name
33
+ * @return Ecocode_Profiler_Block_Renderer_RendererInterface
34
  */
35
+ public function getInstance($name)
36
  {
37
+ if (strpos($name, '/') === false) {
38
+ $name = 'ecocode_profiler/renderer_' . $name;
39
  }
40
+
41
+ if (!isset($this->renderer[$name])) {
42
+ $this->renderer[$name] = Mage::app()->getLayout()->createBlock($name);
43
+ }
44
+
45
+ return $this->renderer[$name];
46
  }
47
  }
app/code/community/Ecocode/Profiler/Helper/Sql.php CHANGED
@@ -9,21 +9,21 @@ class Ecocode_Profiler_Helper_Sql extends Mage_Core_Helper_Abstract
9
 
10
  public function replaceQueryParameters($query, array $parameters)
11
  {
12
- $i = 0;
13
  if (!array_key_exists(0, $parameters) && array_key_exists(1, $parameters)) {
14
- $i = 1;
15
  }
16
 
17
  $result = preg_replace_callback(
18
  '/\?|((?<!:):[a-z0-9_]+)/i',
19
- function ($matches) use ($parameters, &$i) {
20
  $key = substr($matches[0], 1);
21
- if (!array_key_exists($i, $parameters) && (false === $key || !array_key_exists($key, $parameters))) {
22
  return $matches[0];
23
  }
24
- $value = array_key_exists($i, $parameters) ? $parameters[$i] : $parameters[$key];
25
  $result = Mage::getSingleton('core/resource')->getConnection('default_write')->quote($value);
26
- $i++;
27
  return $result;
28
  },
29
  $query
9
 
10
  public function replaceQueryParameters($query, array $parameters)
11
  {
12
+ $index = 0;
13
  if (!array_key_exists(0, $parameters) && array_key_exists(1, $parameters)) {
14
+ $index = 1;
15
  }
16
 
17
  $result = preg_replace_callback(
18
  '/\?|((?<!:):[a-z0-9_]+)/i',
19
+ function ($matches) use ($parameters, &$index) {
20
  $key = substr($matches[0], 1);
21
+ if (!array_key_exists($index, $parameters) && (false === $key || !array_key_exists($key, $parameters))) {
22
  return $matches[0];
23
  }
24
+ $value = array_key_exists($index, $parameters) ? $parameters[$index] : $parameters[$key];
25
  $result = Mage::getSingleton('core/resource')->getConnection('default_write')->quote($value);
26
+ $index++;
27
  return $result;
28
  },
29
  $query
app/code/community/Ecocode/Profiler/Helper/ValueExporter.php CHANGED
@@ -46,25 +46,25 @@ class Ecocode_Profiler_Helper_ValueExporter
46
 
47
  $indent = str_repeat(' ', $depth);
48
 
49
- $a = [];
50
- foreach ($value as $k => $v) {
51
- if (is_array($v)) {
52
  $deep = true;
53
  }
54
- $a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
55
  }
56
 
57
  if ($deep) {
58
- return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1));
59
  }
60
 
61
- $s = sprintf('[%s]', implode(', ', $a));
62
 
63
- if (80 > strlen($s)) {
64
- return $s;
65
  }
66
 
67
- return sprintf("[\n%s%s\n]", $indent, implode(sprintf(",\n%s", $indent), $a));
68
  }
69
 
70
  if (is_resource($value)) {
46
 
47
  $indent = str_repeat(' ', $depth);
48
 
49
+ $all = [];
50
+ foreach ($value as $key => $val) {
51
+ if (is_array($val)) {
52
  $deep = true;
53
  }
54
+ $all[] = sprintf('%s => %s', $key, $this->exportValue($val, $depth + 1, $deep));
55
  }
56
 
57
  if ($deep) {
58
+ return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $all), str_repeat(' ', $depth - 1));
59
  }
60
 
61
+ $str = sprintf('[%s]', implode(', ', $all));
62
 
63
+ if (80 > strlen($str)) {
64
+ return $str;
65
  }
66
 
67
+ return sprintf("[\n%s%s\n]", $indent, implode(sprintf(",\n%s", $indent), $all));
68
  }
69
 
70
  if (is_resource($value)) {
app/code/community/Ecocode/Profiler/Model/AppDev.php CHANGED
@@ -35,7 +35,10 @@ class Ecocode_Profiler_Model_AppDev extends Mage_Core_Model_App
35
 
36
  public function setErrorHandler($handler)
37
  {
38
- //DONT SET WE ARE USING THE SYMFONY DEBUG ONE
 
 
 
39
  }
40
 
41
 
35
 
36
  public function setErrorHandler($handler)
37
  {
38
+ if (!@class_exists('\Symfony\Component\Debug\Debug')) {
39
+ //only call if symfony debug is not available
40
+ parent::setErrorHandler($handler);
41
+ }
42
  }
43
 
44
 
app/code/community/Ecocode/Profiler/Model/Collector/AbstractDataCollector.php CHANGED
@@ -9,33 +9,32 @@ abstract class Ecocode_Profiler_Model_Collector_AbstractDataCollector
9
  {
10
  protected $data = [];
11
 
 
12
  protected $contextHelper;
13
 
14
-
15
  public function init()
16
  {
17
  //fill if needed
18
  }
19
 
 
 
 
 
20
  public function serialize()
21
  {
22
  return serialize($this->data);
23
  }
24
 
 
 
 
 
25
  public function unserialize($data)
26
  {
27
  $this->data = unserialize($data);
28
  }
29
 
30
- public function getBlockPanelName()
31
- {
32
- return $this->getName() . '_panel';
33
- }
34
-
35
- public function getBlockMenuName()
36
- {
37
- return $this->getName() . '_menu';
38
- }
39
 
40
  public function getBlockToolbarName()
41
  {
@@ -60,6 +59,7 @@ abstract class Ecocode_Profiler_Model_Collector_AbstractDataCollector
60
  }
61
 
62
  /**
 
63
  * @return Ecocode_Profiler_Helper_Context
64
  */
65
  public function getContextHelper()
@@ -71,6 +71,24 @@ abstract class Ecocode_Profiler_Model_Collector_AbstractDataCollector
71
  return $this->contextHelper;
72
  }
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  protected function getBacktrace($options = DEBUG_BACKTRACE_PROVIDE_OBJECT)
75
  {
76
  if (!function_exists('debug_backtrace')) {
9
  {
10
  protected $data = [];
11
 
12
+ protected $helper;
13
  protected $contextHelper;
14
 
 
15
  public function init()
16
  {
17
  //fill if needed
18
  }
19
 
20
+ /**
21
+ * @codeCoverageIgnore
22
+ * @return string
23
+ */
24
  public function serialize()
25
  {
26
  return serialize($this->data);
27
  }
28
 
29
+ /**
30
+ * @codeCoverageIgnore
31
+ * @param string $data
32
+ */
33
  public function unserialize($data)
34
  {
35
  $this->data = unserialize($data);
36
  }
37
 
 
 
 
 
 
 
 
 
 
38
 
39
  public function getBlockToolbarName()
40
  {
59
  }
60
 
61
  /**
62
+ * @codeCoverageIgnore
63
  * @return Ecocode_Profiler_Helper_Context
64
  */
65
  public function getContextHelper()
71
  return $this->contextHelper;
72
  }
73
 
74
+ /**
75
+ * @codeCoverageIgnore
76
+ * @return Ecocode_Profiler_Helper_Data
77
+ */
78
+ protected function getHelper()
79
+ {
80
+ if ($this->helper === null) {
81
+ $this->helper = Mage::helper('ecocode_profiler');
82
+ }
83
+
84
+ return $this->helper;
85
+ }
86
+
87
+ /**
88
+ * @codeCoverageIgnore
89
+ * @param int $options
90
+ * @return array|bool
91
+ */
92
  protected function getBacktrace($options = DEBUG_BACKTRACE_PROVIDE_OBJECT)
93
  {
94
  if (!function_exists('debug_backtrace')) {
app/code/community/Ecocode/Profiler/Model/Collector/ConfigDataCollector.php CHANGED
@@ -6,6 +6,8 @@
6
  class Ecocode_Profiler_Model_Collector_ConfigDataCollector
7
  extends Ecocode_Profiler_Model_Collector_AbstractDataCollector
8
  {
 
 
9
 
10
  /**
11
  * {@inheritdoc}
@@ -15,25 +17,25 @@ class Ecocode_Profiler_Model_Collector_ConfigDataCollector
15
  $store = Mage::app()->getStore();
16
  $website = Mage::app()->getWebsite();
17
 
18
- $this->data = [
19
- 'store_id' => $store->getId(),
20
- 'store_name' => $store->getName(),
21
- 'store_code' => $store->getCode(),
22
- 'website_id' => $website->getId(),
23
- 'website_name' => $website->getName(),
24
- 'website_code' => $website->getCode(),
25
- 'developer_mode' => Mage::getIsDeveloperMode(),
26
- 'token' => $this->retrieveToken($response),
27
- 'magento_version' => Mage::getVersion(),
28
- 'magento_modules' => $this->collectMagentoModules(),
29
- 'php_version' => PHP_VERSION,
30
- 'xdebug_enabled' => extension_loaded('xdebug'),
31
- 'eaccel_enabled' => extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'),
32
- 'apc_enabled' => extension_loaded('apc') && ini_get('apc.enabled'),
33
- 'xcache_enabled' => extension_loaded('xcache') && ini_get('xcache.cacher'),
34
- 'wincache_enabled' => extension_loaded('wincache') && ini_get('wincache.ocenabled'),
35
- 'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),
36
- 'sapi_name' => PHP_SAPI,
37
  ];
38
 
39
  }
@@ -215,14 +217,7 @@ class Ecocode_Profiler_Model_Collector_ConfigDataCollector
215
 
216
  public function retrieveToken(Mage_Core_Controller_Response_Http $response)
217
  {
218
- $token = null;
219
- foreach ($response->getHeaders() as $header) {
220
- if ($header['name'] === 'X-Debug-Token') {
221
- $token = $header['value'];
222
- break;
223
- }
224
- }
225
- return $token;
226
  }
227
 
228
  /**
@@ -233,5 +228,4 @@ class Ecocode_Profiler_Model_Collector_ConfigDataCollector
233
  {
234
  return 'config';
235
  }
236
-
237
  }
6
  class Ecocode_Profiler_Model_Collector_ConfigDataCollector
7
  extends Ecocode_Profiler_Model_Collector_AbstractDataCollector
8
  {
9
+ /** @var Ecocode_Profiler_Helper_Data */
10
+ protected $helper;
11
 
12
  /**
13
  * {@inheritdoc}
17
  $store = Mage::app()->getStore();
18
  $website = Mage::app()->getWebsite();
19
 
20
+ $this->data = [
21
+ 'store_id' => $store->getId(),
22
+ 'store_name' => $store->getName(),
23
+ 'store_code' => $store->getCode(),
24
+ 'website_id' => $website->getId(),
25
+ 'website_name' => $website->getName(),
26
+ 'website_code' => $website->getCode(),
27
+ 'developer_mode' => Mage::getIsDeveloperMode(),
28
+ 'token' => $this->retrieveToken($response),
29
+ 'magento_version' => Mage::getVersion(),
30
+ 'magento_modules' => $this->collectMagentoModules(),
31
+ 'php_version' => PHP_VERSION,
32
+ 'xdebug_enabled' => extension_loaded('xdebug'),
33
+ 'eaccel_enabled' => extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'),
34
+ 'apc_enabled' => extension_loaded('apc') && ini_get('apc.enabled'),
35
+ 'xcache_enabled' => extension_loaded('xcache') && ini_get('xcache.cacher'),
36
+ 'wincache_enabled' => extension_loaded('wincache') && ini_get('wincache.ocenabled'),
37
+ 'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),
38
+ 'sapi_name' => PHP_SAPI,
39
  ];
40
 
41
  }
217
 
218
  public function retrieveToken(Mage_Core_Controller_Response_Http $response)
219
  {
220
+ return $this->getHelper()->getTokenFromResponse($response);
 
 
 
 
 
 
 
221
  }
222
 
223
  /**
228
  {
229
  return 'config';
230
  }
 
231
  }
app/code/community/Ecocode/Profiler/Model/Collector/LayoutDataCollector.php CHANGED
@@ -56,8 +56,6 @@ class Ecocode_Profiler_Model_Collector_LayoutDataCollector
56
 
57
  $this->renderedBlocks[$id] = $block;
58
  $this->renderLog[$id] = $data;
59
-
60
-
61
  }
62
 
63
  /**
@@ -70,32 +68,16 @@ class Ecocode_Profiler_Model_Collector_LayoutDataCollector
70
 
71
  $layout = $this->getLayout();
72
  $outputBlocks = [];
73
- foreach ($outputProperties->getValue($layout) as $name => $data) {
 
74
  $block = $layout->getBlock($name);
75
  $outputBlocks[] = $block->getData('profiler_id');
76
  }
77
 
78
- $totalTime = 0;
79
- foreach ($this->renderLog as &$data) {
80
- $renderTimeExcl = $data['render_time_incl'];
81
- foreach ($data['children'] as $childId) {
82
- $child = $this->renderLog[$childId];
83
- $renderTimeExcl -= $child['render_time_incl'];
84
- }
85
- $data['render_time'] = $renderTimeExcl;
86
 
87
- $totalTime += $data['render_time'];
88
- }
89
-
90
- $renderedCount = 0;
91
- $notRenderedBlocks = [];
92
- foreach ($layout->getAllBlocks() as $block) {
93
- if ($block->getData('profiler_id')) {
94
- $renderedCount++;
95
- } else {
96
- $notRenderedBlocks[] = $this->getBaseBlockData($block);
97
- }
98
- }
99
  $this->data = [
100
  'handles' => $layout->getUpdate()->getHandles(),
101
  'blocks_created_count' => count($layout->getAllBlocks()),
@@ -107,9 +89,52 @@ class Ecocode_Profiler_Model_Collector_LayoutDataCollector
107
  'render_time' => $totalTime
108
 
109
  ];
 
110
  return $this;
111
  }
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  protected function getBaseBlockData(Mage_Core_Block_Abstract $block)
114
  {
115
  return [
@@ -153,7 +178,6 @@ class Ecocode_Profiler_Model_Collector_LayoutDataCollector
153
  }
154
 
155
 
156
-
157
  /**
158
  * @codeCoverageIgnore
159
  * @return Mage_Core_Model_Layout
56
 
57
  $this->renderedBlocks[$id] = $block;
58
  $this->renderLog[$id] = $data;
 
 
59
  }
60
 
61
  /**
68
 
69
  $layout = $this->getLayout();
70
  $outputBlocks = [];
71
+
72
+ foreach (array_keys($outputProperties->getValue($layout)) as $name) {
73
  $block = $layout->getBlock($name);
74
  $outputBlocks[] = $block->getData('profiler_id');
75
  }
76
 
77
+ $this->clearRenderLog();
78
+ $totalTime = $this->collectTimingData();
79
+ $notRenderedBlocks = $this->collectNotRenderedBlocks();
 
 
 
 
 
80
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  $this->data = [
82
  'handles' => $layout->getUpdate()->getHandles(),
83
  'blocks_created_count' => count($layout->getAllBlocks()),
89
  'render_time' => $totalTime
90
 
91
  ];
92
+
93
  return $this;
94
  }
95
 
96
+ protected function collectNotRenderedBlocks()
97
+ {
98
+ $notRenderedBlocks = [];
99
+
100
+ foreach ($this->getLayout()->getAllBlocks() as $block) {
101
+ /** @var Mage_Core_Block_Abstract $block */
102
+ if (!$block->getData('profiler_id')) {
103
+ $notRenderedBlocks[] = $this->getBaseBlockData($block);
104
+ }
105
+ }
106
+
107
+ return $notRenderedBlocks;
108
+ }
109
+
110
+ protected function clearRenderLog()
111
+ {
112
+ foreach ($this->renderLog as $id => &$data) {
113
+ if (!isset($data['stop_render'])) {
114
+ //block is not rendered, so unset it
115
+ unset($this->renderLog[$id]);
116
+ continue;
117
+ }
118
+ }
119
+ }
120
+
121
+ protected function collectTimingData()
122
+ {
123
+ $totalTime = 0;
124
+ foreach ($this->renderLog as &$data) {
125
+ $renderTimeExcl = $data['render_time_incl'];
126
+ foreach ($data['children'] as $childId) {
127
+ $child = $this->renderLog[$childId];
128
+ $renderTimeExcl -= $child['render_time_incl'];
129
+ }
130
+ $data['render_time'] = $renderTimeExcl;
131
+
132
+ $totalTime += $data['render_time'];
133
+ }
134
+
135
+ return $totalTime;
136
+ }
137
+
138
  protected function getBaseBlockData(Mage_Core_Block_Abstract $block)
139
  {
140
  return [
178
  }
179
 
180
 
 
181
  /**
182
  * @codeCoverageIgnore
183
  * @return Mage_Core_Model_Layout
app/code/community/Ecocode/Profiler/Model/Collector/ModelDataCollector.php CHANGED
@@ -57,8 +57,8 @@ class Ecocode_Profiler_Model_Collector_ModelDataCollector
57
  $totalTime += $item['time'];
58
  }
59
 
60
- $traceHashList = array_filter($traceHashList, function ($v) {
61
- return $v > 1;
62
  });
63
 
64
  $stats['loop_load'] = array_sum($traceHashList);
@@ -90,12 +90,12 @@ class Ecocode_Profiler_Model_Collector_ModelDataCollector
90
  $traceHashList[$traceHash]['total_time'] += $item['time'];
91
  }
92
 
93
- $traceHashList = array_filter($traceHashList, function ($v) {
94
- return $v['count'] > 1;
95
  });
96
 
97
- usort($traceHashList, function ($a, $b) {
98
- return $b['count'] - $a['count'];
99
  });
100
 
101
  return array_values($traceHashList);
@@ -150,7 +150,7 @@ class Ecocode_Profiler_Model_Collector_ModelDataCollector
150
  protected function track($action, Varien_Object $object, $time = null)
151
  {
152
  $className = get_class($object);
153
- $classGroup = $this->getHelper()->getClassGroup($className);
154
  $trace = $this->cleanBacktrace($this->getBacktrace(DEBUG_BACKTRACE_IGNORE_ARGS));
155
 
156
  $data = [
57
  $totalTime += $item['time'];
58
  }
59
 
60
+ $traceHashList = array_filter($traceHashList, function ($count) {
61
+ return $count > 1;
62
  });
63
 
64
  $stats['loop_load'] = array_sum($traceHashList);
90
  $traceHashList[$traceHash]['total_time'] += $item['time'];
91
  }
92
 
93
+ $traceHashList = array_filter($traceHashList, function ($trace) {
94
+ return $trace['count'] > 1;
95
  });
96
 
97
+ usort($traceHashList, function ($trace1, $trace2) {
98
+ return $trace2['count'] - $trace1['count'];
99
  });
100
 
101
  return array_values($traceHashList);
150
  protected function track($action, Varien_Object $object, $time = null)
151
  {
152
  $className = get_class($object);
153
+ $classGroup = $this->getHelper()->resolveClassGroup($className);
154
  $trace = $this->cleanBacktrace($this->getBacktrace(DEBUG_BACKTRACE_IGNORE_ARGS));
155
 
156
  $data = [
app/code/community/Ecocode/Profiler/Model/Collector/RequestDataCollector.php CHANGED
@@ -6,6 +6,8 @@
6
  class Ecocode_Profiler_Model_Collector_RequestDataCollector
7
  extends Ecocode_Profiler_Model_Collector_AbstractDataCollector
8
  {
 
 
9
  public static $statusTexts = [
10
  100 => 'Continue',
11
  101 => 'Switching Protocols',
@@ -81,23 +83,6 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
81
  $requestHeaders = $this->collectRequestHeaders($request);
82
  $requestContent = $request->getRawBody();
83
 
84
- $sessionMetadata = [];
85
- $sessionAttributes = [];
86
- //@TODO get all magento session singletons to split them by namespace
87
- $flashes = [];
88
-
89
- /*
90
- $session = null
91
- if (false && $request->hasSession()) {
92
- $session = $request->getSession();
93
- if ($session->isStarted()) {
94
- $sessionMetadata['Created'] = date(DATE_RFC822, $session->getMetadataBag()->getCreated());
95
- $sessionMetadata['Last used'] = date(DATE_RFC822, $session->getMetadataBag()->getLastUsed());
96
- $sessionMetadata['Lifetime'] = $session->getMetadataBag()->getLifetime();
97
- $sessionAttributes = $session->all();
98
- $flashes = $session->getFlashBag()->peekAll();
99
- }
100
- }*/
101
 
102
  $statusCode = $this->detectStatusCode($response);
103
  $statusText = isset(self::$statusTexts[$statusCode]) ? self::$statusTexts[$statusCode] : '';
@@ -117,9 +102,9 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
117
  'request_cookies' => $request->getCookie(),
118
  'request_attributes' => $requestAttributes,
119
  'response_headers' => $responseHeaders,
120
- 'session_metadata' => $sessionMetadata,
121
- 'session_attributes' => $sessionAttributes,
122
- 'flashes' => $flashes,
123
  'path_info' => $request->getPathInfo(),
124
  'controller' => 'n/a',
125
  //'locale' => $request->getLocale(),
@@ -132,22 +117,139 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
132
  $this->data['controller'] = $controllerData;
133
  }
134
 
135
- /*if (null !== $session && $session->isStarted()) {
136
- if ($request->attributes->has('_redirected')) {
137
- $this->data['redirect'] = $session->remove('sf_redirect');
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
139
 
140
  if ($response->isRedirect()) {
141
- $session->set('sf_redirect', [
142
- 'token' => $response->headers->get('x-debug-token'),
143
- 'route' => $request->attributes->get('_route', 'n/a'),
144
  'method' => $request->getMethod(),
145
- 'controller' => $this->parseController($request->attributes->get('_controller')),
146
- 'status_code' => $statusCode,
147
- 'status_text' => Response::$statusTexts[(int)$statusCode],
148
  ]);
149
  }
150
- }*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  }
152
 
153
  protected function hideAuthData()
@@ -217,12 +319,12 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
217
 
218
  public function getSessionAttributes()
219
  {
220
- return $this->data['session_attributes'];
221
  }
222
 
223
- public function getFlashes()
224
  {
225
- return $this->data['flashes'];
226
  }
227
 
228
  public function getContent()
@@ -331,7 +433,7 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
331
  */
332
  public function getController()
333
  {
334
- return $this->data['controller'];
335
  }
336
 
337
  /**
@@ -342,9 +444,18 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
342
  */
343
  public function getRedirect()
344
  {
345
- return isset($this->data['redirect']) ? $this->data['redirect'] : false;
346
  }
347
 
 
 
 
 
 
 
 
 
 
348
 
349
  /**
350
  * {@inheritdoc}
@@ -365,19 +476,50 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
365
  protected function parseController($controller)
366
  {
367
  if (is_object($controller)) {
368
- $r = new \ReflectionClass($controller);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
 
370
  return [
371
- 'class' => $r->getName(),
372
  'method' => null,
373
- 'file' => $r->getFileName(),
374
- 'line' => $r->getStartLine(),
375
  ];
376
  }
377
 
378
  return (string)$controller ?: 'n/a';
379
  }
380
 
 
 
 
 
 
 
 
381
  protected function detectStatusCode(Mage_Core_Controller_Response_Http $response)
382
  {
383
  $statusCode = $response->getHttpResponseCode();
@@ -422,13 +564,13 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
422
  $attributes['_route_params'] = $routeParams;
423
  }
424
 
425
-
426
  return $attributes;
427
  }
428
 
429
  public function collectRequestHeaders(Mage_Core_Controller_Request_Http $request)
430
  {
431
  $headers = [];
 
432
  foreach ($request->getServer() as $key => $value) {
433
  if (substr($key, 0, 5) !== 'HTTP_') {
434
  continue;
@@ -436,26 +578,23 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
436
  $header = str_replace(' ', '-', (str_replace('_', ' ', strtolower(substr($key, 5)))));
437
  $headers[$header] = $value;
438
  }
 
439
  return $headers;
440
  }
441
 
442
  public function collectRequestQuery(Mage_Core_Controller_Request_Http $request)
443
  {
444
- $getData = $request->getQuery();
445
- if ($getData === null) {
446
- $getData = [];
447
- }
448
- return $getData;
449
  }
450
 
451
 
452
  public function collectRequestData(Mage_Core_Controller_Request_Http $request)
453
  {
454
  $postData = $request->getPost();
455
- if ($postData === null) {
456
- $postData = [];
457
- }
458
- return $postData;
459
  }
460
 
461
  protected function collectControllerData()
@@ -468,7 +607,9 @@ class Ecocode_Profiler_Model_Collector_RequestDataCollector
468
 
469
  $app = Mage::app();
470
  $controller = $property->getValue($app);
 
471
  if ($controller) {
 
472
  return $this->parseController($controller);
473
  }
474
 
6
  class Ecocode_Profiler_Model_Collector_RequestDataCollector
7
  extends Ecocode_Profiler_Model_Collector_AbstractDataCollector
8
  {
9
+ protected $messages = [];
10
+
11
  public static $statusTexts = [
12
  100 => 'Continue',
13
  101 => 'Switching Protocols',
83
  $requestHeaders = $this->collectRequestHeaders($request);
84
  $requestContent = $request->getRawBody();
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  $statusCode = $this->detectStatusCode($response);
88
  $statusText = isset(self::$statusTexts[$statusCode]) ? self::$statusTexts[$statusCode] : '';
102
  'request_cookies' => $request->getCookie(),
103
  'request_attributes' => $requestAttributes,
104
  'response_headers' => $responseHeaders,
105
+ 'session_metadata' => [],
106
+ 'session_data' => [],
107
+ 'messages' => [],
108
  'path_info' => $request->getPathInfo(),
109
  'controller' => 'n/a',
110
  //'locale' => $request->getLocale(),
117
  $this->data['controller'] = $controllerData;
118
  }
119
 
120
+ $this->collectRedirectData($request, $response);
121
+ $this->collectSessionData();
122
+ $this->collectFlashMessages();
123
+ }
124
+
125
+ protected function collectRedirectData(
126
+ Mage_Core_Controller_Request_Http $request,
127
+ Mage_Core_Controller_Response_Http $response
128
+ )
129
+ {
130
+ /** @var $session Ecocode_Profiler_Model_Session $session */
131
+ $session = $this->getHelper()->getSession();
132
+ if (null !== $session) {
133
+ if ($request->getParam('_redirected')) {
134
+ $this->data['redirect'] = $session->getData('eco_redirect', true);
135
  }
136
 
137
  if ($response->isRedirect()) {
138
+ $session->setData('eco_redirect', [
139
+ 'token' => $this->getHelper()->getTokenFromResponse($response),
140
+ 'route' => $this->getRoute(),
141
  'method' => $request->getMethod(),
142
+ 'controller' => $this->getController(),
143
+ 'status_code' => $this->getStatusCode(),
144
+ 'status_text' => $this->getStatusText(),
145
  ]);
146
  }
147
+ }
148
+ }
149
+
150
+ protected function collectSessionData()
151
+ {
152
+ $namespaceData = [];
153
+ $storeData = [];
154
+ $rawSessionData = $this->getRawSession();
155
+
156
+ $defaultSessionData = [
157
+ '_session_validator_data' => false,
158
+ 'session_hosts' => false
159
+ ];
160
+
161
+
162
+ foreach ($rawSessionData as $key => $data) {
163
+ if (isset($data['messages'])) {
164
+ //dont save messages here
165
+ unset($data['messages']);
166
+ }
167
+
168
+ if (isset($data['_session_validator_data'])) {
169
+ unset($rawSessionData[$key]);
170
+ //magento session model
171
+ $filtered = array_diff_key($data, $defaultSessionData);
172
+
173
+ if (count($filtered) === 0) {
174
+ continue;
175
+ }
176
+
177
+ if (strpos($key, 'store_') === 0) {
178
+ $storeCode = str_replace('store_', '', $key);
179
+ $storeData[$storeCode] = $data;
180
+ } else {
181
+ $namespaceData[$key] = $data;
182
+ }
183
+
184
+
185
+ }
186
+
187
+ }
188
+ //add the missing data to a global namespace
189
+ $this->data['session_data'] = [
190
+ 'namespace' => $namespaceData,
191
+ 'store' => $storeData,
192
+ 'global' => $rawSessionData,
193
+ ];
194
+ }
195
+
196
+ /**
197
+ * @return Mage_Core_Model_Message_Collection
198
+ */
199
+ protected function getSessionList()
200
+ {
201
+ $rawSessionData = $this->getRawSession();
202
+ $sessionList = [];
203
+ foreach (Mage::getAllRegistryEntries() as $session) {
204
+ if ($session instanceof Mage_Core_Model_Session_Abstract) {
205
+ $namespace = array_search($session->getData(), $rawSessionData);
206
+ $sessionList[$namespace] = $session;
207
+ }
208
+ }
209
+
210
+ return $sessionList;
211
+ }
212
+
213
+ protected function collectFlashMessages()
214
+ {
215
+ $messages = [];
216
+ $sessionList = $this->getSessionList();
217
+ $helper = $this->getHelper();
218
+
219
+ foreach ($this->messages as $message) {
220
+ $namespace = $message['namespace'];
221
+
222
+ $session = $sessionList[$namespace];
223
+ $message['class_group'] = $helper->resolveClassGroup($session);
224
+
225
+ $messages[] = $message;
226
+ }
227
+
228
+ $this->data['messages'] = $messages;
229
+ }
230
+
231
+ public function captureFlashMessages()
232
+ {
233
+ $messages = [];
234
+ foreach ($this->getRawSession() as $namespace => $data) {
235
+ if (!isset($data['messages'])) {
236
+ continue;
237
+ }
238
+
239
+ if ($data['messages']->count()) {
240
+ foreach ($data['messages']->getItems() as $message) {
241
+ /** @var Mage_Core_Model_Message_Abstract $message */
242
+
243
+ $messages[] = [
244
+ 'namespace' => $namespace,
245
+ 'type' => $message->getType(),
246
+ 'text' => $message->getText(),
247
+ ];
248
+ }
249
+ }
250
+ }
251
+
252
+ $this->messages = $messages;
253
  }
254
 
255
  protected function hideAuthData()
319
 
320
  public function getSessionAttributes()
321
  {
322
+ return $this->data['session_data'];
323
  }
324
 
325
+ public function getMessages()
326
  {
327
+ return $this->data['messages'];
328
  }
329
 
330
  public function getContent()
433
  */
434
  public function getController()
435
  {
436
+ return $this->getData('controller', []);
437
  }
438
 
439
  /**
444
  */
445
  public function getRedirect()
446
  {
447
+ return $this->getData('redirect', false);
448
  }
449
 
450
+ /**
451
+ * @codeCoverageIgnore
452
+ * @SuppressWarnings("superglobals")
453
+ * @return array
454
+ */
455
+ protected function getRawSession()
456
+ {
457
+ return isset($_SESSION) ? $_SESSION : [];
458
+ }
459
 
460
  /**
461
  * {@inheritdoc}
476
  protected function parseController($controller)
477
  {
478
  if (is_object($controller)) {
479
+ /** @var Mage_Core_Controller_Varien_Front $controller */
480
+
481
+ if ($controller->getData('action')) {
482
+ /** @var Mage_Core_Controller_Varien_Action $actionController */
483
+ $actionController = $controller->getData('action');
484
+
485
+ /** @var Mage_Core_Controller_Request_Http $request */
486
+ $request = $actionController->getRequest();
487
+
488
+ if ($actionController->hasAction($request->getActionName())) {
489
+ $actionReflection = new \ReflectionMethod(
490
+ $actionController,
491
+ $actionController->getActionMethodName($request->getActionName())
492
+ );
493
+
494
+ return [
495
+ 'class' => get_class($actionController),
496
+ 'method' => $actionReflection->getName(),
497
+ 'file' => $actionReflection->getFileName(),
498
+ 'line' => $actionReflection->getStartLine(),
499
+ ];
500
+ }
501
+ }
502
+
503
+ $controllerReflection = new \ReflectionClass($controller);
504
 
505
  return [
506
+ 'class' => $controllerReflection->getName(),
507
  'method' => null,
508
+ 'file' => $controllerReflection->getFileName(),
509
+ 'line' => $controllerReflection->getStartLine(),
510
  ];
511
  }
512
 
513
  return (string)$controller ?: 'n/a';
514
  }
515
 
516
+ /**
517
+ * Magento is not very good in setting the right response code
518
+ * so we help out a bit by checking the actual header that is send
519
+ *
520
+ * @param Mage_Core_Controller_Response_Http $response
521
+ * @return int
522
+ */
523
  protected function detectStatusCode(Mage_Core_Controller_Response_Http $response)
524
  {
525
  $statusCode = $response->getHttpResponseCode();
564
  $attributes['_route_params'] = $routeParams;
565
  }
566
 
 
567
  return $attributes;
568
  }
569
 
570
  public function collectRequestHeaders(Mage_Core_Controller_Request_Http $request)
571
  {
572
  $headers = [];
573
+
574
  foreach ($request->getServer() as $key => $value) {
575
  if (substr($key, 0, 5) !== 'HTTP_') {
576
  continue;
578
  $header = str_replace(' ', '-', (str_replace('_', ' ', strtolower(substr($key, 5)))));
579
  $headers[$header] = $value;
580
  }
581
+
582
  return $headers;
583
  }
584
 
585
  public function collectRequestQuery(Mage_Core_Controller_Request_Http $request)
586
  {
587
+ $queryData = $request->getQuery();
588
+
589
+ return $queryData ? $queryData : [];
 
 
590
  }
591
 
592
 
593
  public function collectRequestData(Mage_Core_Controller_Request_Http $request)
594
  {
595
  $postData = $request->getPost();
596
+
597
+ return $postData ? $postData : [];
 
 
598
  }
599
 
600
  protected function collectControllerData()
607
 
608
  $app = Mage::app();
609
  $controller = $property->getValue($app);
610
+
611
  if ($controller) {
612
+ /** @var Mage_Core_Controller_Varien_Action */
613
  return $this->parseController($controller);
614
  }
615
 
app/code/community/Ecocode/Profiler/Model/Collector/TranslationDataCollector.php CHANGED
@@ -26,7 +26,11 @@ class Ecocode_Profiler_Model_Collector_TranslationDataCollector
26
  /**
27
  * {@inheritdoc}
28
  */
29
- public function collect(Mage_Core_Controller_Request_Http $request, Mage_Core_Controller_Response_Http $response, \Exception $exception = null)
 
 
 
 
30
  {
31
 
32
  $this->data['state_counts'] = $this->stateCounts;
@@ -34,23 +38,37 @@ class Ecocode_Profiler_Model_Collector_TranslationDataCollector
34
 
35
  foreach ($this->getTranslator()->getMessages() as $translation) {
36
  $translationId = $translation['code'];
 
 
37
  if (!isset($translations[$translationId])) {
38
- $translation['count'] = 1;
39
- $translation['parameters'] = !empty($translation['parameters']) ? [$translation['parameters']] : [];
40
- $translation['traces'] = !empty($translation['trace']) ? [$translation['trace']] : [];
41
- unset($translation['trace']);
42
  $translations[$translationId] = $translation;
43
  $this->data['state_counts'][$translation['state']]++;
44
- } else {
45
- if (!empty($translation['parameters'])) {
46
- $translations[$translationId]['parameters'][] = $translation['parameters'];
47
- }
48
- if (!empty($translation['trace'])) {
49
- $translations[$translationId]['traces'][] = $translation['trace'];
 
 
 
 
 
 
 
 
 
 
50
  }
51
- $translations[$translationId]['count']++;
52
  }
 
 
53
  }
 
54
  $this->data['translations'] = $translations;
55
  $this->data['translation_count'] = count($translations);
56
  }
26
  /**
27
  * {@inheritdoc}
28
  */
29
+ public function collect(
30
+ Mage_Core_Controller_Request_Http $request,
31
+ Mage_Core_Controller_Response_Http $response,
32
+ \Exception $exception = null
33
+ )
34
  {
35
 
36
  $this->data['state_counts'] = $this->stateCounts;
38
 
39
  foreach ($this->getTranslator()->getMessages() as $translation) {
40
  $translationId = $translation['code'];
41
+ $parameters = $translation['parameters'];
42
+
43
  if (!isset($translations[$translationId])) {
44
+ $translation['count'] = 0;
45
+ $translation['parameters'] = [];
46
+ $translation['traces'] = [];
 
47
  $translations[$translationId] = $translation;
48
  $this->data['state_counts'][$translation['state']]++;
49
+ }
50
+
51
+ if (!empty($parameters)) {
52
+ $translations[$translationId]['parameters'][] = $parameters;
53
+ }
54
+
55
+ if (!empty($translation['trace'])) {
56
+ $traceId = md5(serialize($translation['trace']));
57
+
58
+ //do not capture traces multiple times
59
+ if (!isset($translations[$translationId]['traces'][$traceId])) {
60
+ $translations[$translationId]['traces'][$traceId] = [
61
+ 'id' => $traceId,
62
+ 'count' => 0,
63
+ 'trace' => $translation['trace']
64
+ ];
65
  }
66
+ $translations[$translationId]['traces'][$traceId]['count']++;
67
  }
68
+
69
+ $translations[$translationId]['count']++;
70
  }
71
+
72
  $this->data['translations'] = $translations;
73
  $this->data['translation_count'] = count($translations);
74
  }
app/code/community/Ecocode/Profiler/Model/Context.php CHANGED
@@ -6,6 +6,8 @@
6
  class Ecocode_Profiler_Model_Context
7
  implements Ecocode_Profiler_Model_ContextInterface
8
  {
 
 
9
  protected $parentId = 0;
10
 
11
  /** @var string */
6
  class Ecocode_Profiler_Model_Context
7
  implements Ecocode_Profiler_Model_ContextInterface
8
  {
9
+ protected $id;
10
+
11
  protected $parentId = 0;
12
 
13
  /** @var string */
app/code/community/Ecocode/Profiler/Model/Logger.php CHANGED
@@ -18,7 +18,7 @@ use Monolog\Logger as BaseLogger;
18
  */
19
  class Ecocode_Profiler_Model_Logger
20
  extends BaseLogger
21
- implements Ecocode_Profiler_Model_DebugLoggerInterface
22
  {
23
 
24
  protected static $levelMap = [
@@ -64,14 +64,14 @@ class Ecocode_Profiler_Model_Logger
64
  }
65
 
66
  /**
67
- * Returns a DebugLoggerInterface instance if one is registered with this logger.
68
  *
69
- * @return Ecocode_Profiler_Model_DebugLoggerInterface|null A DebugLoggerInterface instance or null if none is registered
70
  */
71
  private function getDebugLogger()
72
  {
73
  foreach ($this->handlers as $handler) {
74
- if ($handler instanceof Ecocode_Profiler_Model_DebugLoggerInterface) {
75
  return $handler;
76
  }
77
  }
18
  */
19
  class Ecocode_Profiler_Model_Logger
20
  extends BaseLogger
21
+ implements Ecocode_Profiler_Model_LoggerInterface
22
  {
23
 
24
  protected static $levelMap = [
64
  }
65
 
66
  /**
67
+ * Returns a Ecocode_Profiler_Model_Logger_DebugHandlerInterface instance if one is registered with this logger.
68
  *
69
+ * @return Ecocode_Profiler_Model_Logger_DebugHandlerInterface|null A DebugLoggerInterface instance or null if none is registered
70
  */
71
  private function getDebugLogger()
72
  {
73
  foreach ($this->handlers as $handler) {
74
+ if ($handler instanceof Ecocode_Profiler_Model_Logger_DebugHandlerInterface) {
75
  return $handler;
76
  }
77
  }
app/code/community/Ecocode/Profiler/Model/Logger/DebugHandler.php CHANGED
@@ -19,7 +19,7 @@ use Monolog\Handler\TestHandler;
19
  * @author Jordi Boggiano <j.boggiano@seld.be>
20
  */
21
  class Ecocode_Profiler_Model_Logger_DebugHandler extends TestHandler
22
- implements Ecocode_Profiler_Model_DebugLoggerInterface
23
  {
24
  /**
25
  * {@inheritdoc}
19
  * @author Jordi Boggiano <j.boggiano@seld.be>
20
  */
21
  class Ecocode_Profiler_Model_Logger_DebugHandler extends TestHandler
22
+ implements Ecocode_Profiler_Model_Logger_DebugHandlerInterface
23
  {
24
  /**
25
  * {@inheritdoc}
app/code/community/Ecocode/Profiler/Model/Logger/DebugHandlerInterface.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * Ecocode_Profiler_Model_Logger_DebugHandlerInterface.
6
+ *
7
+ * @author Fabien Potencier <fabien@symfony.com>
8
+ */
9
+ interface Ecocode_Profiler_Model_Logger_DebugHandlerInterface
10
+ {
11
+ /**
12
+ * Returns an array of logs.
13
+ *
14
+ * A log is an array with the following mandatory keys:
15
+ * timestamp, message, priority, and priorityName.
16
+ * It can also have an optional context key containing an array.
17
+ *
18
+ * @return array An array of logs
19
+ */
20
+ public function getLogs();
21
+
22
+ /**
23
+ * Returns the number of errors.
24
+ *
25
+ * @return int The number of errors
26
+ */
27
+ public function countErrors();
28
+ }
app/code/community/Ecocode/Profiler/Model/LoggerInterface.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ interface Ecocode_Profiler_Model_LoggerInterface
4
+ extends Ecocode_Profiler_Model_Logger_DebugHandlerInterface
5
+ {
6
+ public function mageLog($level, $message, array $context = []);
7
+ }
app/code/community/Ecocode/Profiler/Model/NullLogger.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Ecocode_Profiler_Model_NullLogger
5
+ *
6
+ * @SuppressWarnings("unused")
7
+ */
8
+ class Ecocode_Profiler_Model_NullLogger
9
+ implements Ecocode_Profiler_Model_LoggerInterface
10
+ {
11
+ public function mageLog($level, $message, array $context = [])
12
+ {
13
+ return true;
14
+ }
15
+
16
+ public function getLogs()
17
+ {
18
+ return [];
19
+ }
20
+
21
+ /**
22
+ * {@inheritdoc}
23
+ */
24
+ public function countErrors()
25
+ {
26
+ return 0;
27
+ }
28
+
29
+
30
+ /**
31
+ * System is unusable.
32
+ *
33
+ * @param string $message
34
+ * @param array $context
35
+ *
36
+ * @return void
37
+ */
38
+ public function emergency($message, array $context = [])
39
+ {
40
+ }
41
+
42
+ /**
43
+ * Action must be taken immediately.
44
+ *
45
+ * Example: Entire website down, database unavailable, etc. This should
46
+ * trigger the SMS alerts and wake you up.
47
+ *
48
+ * @param string $message
49
+ * @param array $context
50
+ *
51
+ * @return void
52
+ */
53
+ public function alert($message, array $context = [])
54
+ {
55
+ }
56
+
57
+ /**
58
+ * Critical conditions.
59
+ *
60
+ * Example: Application component unavailable, unexpected exception.
61
+ *
62
+ * @param string $message
63
+ * @param array $context
64
+ *
65
+ * @return void
66
+ */
67
+ public function critical($message, array $context = [])
68
+ {
69
+ }
70
+
71
+ /**
72
+ * Runtime errors that do not require immediate action but should typically
73
+ * be logged and monitored.
74
+ *
75
+ * @param string $message
76
+ * @param array $context
77
+ *
78
+ * @return void
79
+ */
80
+ public function error($message, array $context = [])
81
+ {
82
+ }
83
+
84
+ /**
85
+ * Exceptional occurrences that are not errors.
86
+ *
87
+ * Example: Use of deprecated APIs, poor use of an API, undesirable things
88
+ * that are not necessarily wrong.
89
+ *
90
+ * @param string $message
91
+ * @param array $context
92
+ *
93
+ * @return void
94
+ */
95
+ public function warning($message, array $context = [])
96
+ {
97
+ }
98
+
99
+ /**
100
+ * Normal but significant events.
101
+ *
102
+ * @param string $message
103
+ * @param array $context
104
+ *
105
+ * @return void
106
+ */
107
+ public function notice($message, array $context = [])
108
+ {
109
+ }
110
+
111
+ /**
112
+ * Interesting events.
113
+ *
114
+ * Example: User logs in, SQL logs.
115
+ *
116
+ * @param string $message
117
+ * @param array $context
118
+ *
119
+ * @return void
120
+ */
121
+ public function info($message, array $context = [])
122
+ {
123
+ }
124
+
125
+ /**
126
+ * Detailed debug information.
127
+ *
128
+ * @param string $message
129
+ * @param array $context
130
+ *
131
+ * @return void
132
+ */
133
+ public function debug($message, array $context = [])
134
+ {
135
+ }
136
+
137
+ /**
138
+ * Logs with an arbitrary level.
139
+ *
140
+ * @param mixed $level
141
+ * @param string $message
142
+ * @param array $context
143
+ *
144
+ * @return void
145
+ */
146
+ public function log($level, $message, array $context = [])
147
+ {
148
+ }
149
+ }
app/code/community/Ecocode/Profiler/Model/Observer.php CHANGED
@@ -44,6 +44,7 @@ class Ecocode_Profiler_Model_Observer
44
  $response->setHeader('X-Debug-Token-Link', $url);
45
  }
46
 
 
47
  $this->injectToolbar($response, $request, $token);
48
  }
49
 
@@ -105,6 +106,26 @@ class Ecocode_Profiler_Model_Observer
105
  }
106
 
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  /**
109
  * @codeCoverageIgnore
110
  * @return Mage_Core_Model_Layout
44
  $response->setHeader('X-Debug-Token-Link', $url);
45
  }
46
 
47
+
48
  $this->injectToolbar($response, $request, $token);
49
  }
50
 
106
  }
107
 
108
 
109
+ /**
110
+ * @codeCoverageIgnore
111
+ */
112
+ public function checkRedirect()
113
+ {
114
+ if (Mage::getSingleton('ecocode_profiler/session')->getData('eco_redirect')) {
115
+ Mage::app()->getRequest()->setParam('_redirected', true);
116
+ }
117
+ }
118
+
119
+ public function captureFlashMessages()
120
+ {
121
+ $collector = $this->getProfiler()->getDataCollector('request');
122
+ /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $collector */
123
+ if($collector) {
124
+ $collector->captureFlashMessages();
125
+ }
126
+ }
127
+
128
+
129
  /**
130
  * @codeCoverageIgnore
131
  * @return Mage_Core_Model_Layout
app/code/community/Ecocode/Profiler/Model/Observer/Context.php CHANGED
@@ -13,6 +13,11 @@ class Ecocode_Profiler_Model_Observer_Context
13
  $event = $observer->getEvent();
14
  $block = $event->getData('block');
15
 
 
 
 
 
 
16
  $data = [
17
  'class' => get_class($block),
18
  'module' => $block->getModuleName()
@@ -30,6 +35,7 @@ class Ecocode_Profiler_Model_Observer_Context
30
  $event = $observer->getEvent();
31
  $block = $event->getData('block');
32
 
 
33
  if ($context = $block->getData('__context')) {
34
  if ($block instanceof Mage_Core_Block_Template) {
35
  $context->addData('template', $block->getTemplate());
@@ -52,4 +58,18 @@ class Ecocode_Profiler_Model_Observer_Context
52
 
53
  return $this->helper;
54
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
13
  $event = $observer->getEvent();
14
  $block = $event->getData('block');
15
 
16
+ if (!$this->canOpenBlockContext($block)) {
17
+ //do not open block context as it would not get closed
18
+ return;
19
+ }
20
+
21
  $data = [
22
  'class' => get_class($block),
23
  'module' => $block->getModuleName()
35
  $event = $observer->getEvent();
36
  $block = $event->getData('block');
37
 
38
+ /** @var Ecocode_Profiler_Model_Context $context */
39
  if ($context = $block->getData('__context')) {
40
  if ($block instanceof Mage_Core_Block_Template) {
41
  $context->addData('template', $block->getTemplate());
58
 
59
  return $this->helper;
60
  }
61
+
62
+ /**
63
+ * @codeCoverageIgnore
64
+ * @param Mage_Core_Block_Abstract $block
65
+ * @return bool
66
+ */
67
+ public function canOpenBlockContext(Mage_Core_Block_Abstract $block)
68
+ {
69
+ if (Mage::getStoreConfig('advanced/modules_disable_output/' . $block->getModuleName())) {
70
+ return false;
71
+ }
72
+
73
+ return true;
74
+ }
75
  }
app/code/community/Ecocode/Profiler/Model/Profile.php CHANGED
@@ -12,7 +12,7 @@ class Ecocode_Profiler_Model_Profile
12
  /**
13
  * @var \Ecocode_Profiler_Model_Collector_DataCollectorInterface[]
14
  */
15
- protected $collectors = array();
16
 
17
  protected $ip;
18
  protected $method;
@@ -29,7 +29,7 @@ class Ecocode_Profiler_Model_Profile
29
  /**
30
  * @var Ecocode_Profiler_Model_Profile[]
31
  */
32
- protected $children = array();
33
 
34
  /**
35
  * Constructor.
@@ -202,7 +202,7 @@ class Ecocode_Profiler_Model_Profile
202
  */
203
  public function setChildren(array $children)
204
  {
205
- $this->children = array();
206
  foreach ($children as $child) {
207
  $this->addChild($child);
208
  }
@@ -254,7 +254,7 @@ class Ecocode_Profiler_Model_Profile
254
  */
255
  public function setCollectors(array $collectors)
256
  {
257
- $this->collectors = array();
258
  foreach ($collectors as $collector) {
259
  $this->addCollector($collector);
260
  }
@@ -284,6 +284,6 @@ class Ecocode_Profiler_Model_Profile
284
 
285
  public function __sleep()
286
  {
287
- return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode', 'collectTime');
288
  }
289
  }
12
  /**
13
  * @var \Ecocode_Profiler_Model_Collector_DataCollectorInterface[]
14
  */
15
+ protected $collectors = [];
16
 
17
  protected $ip;
18
  protected $method;
29
  /**
30
  * @var Ecocode_Profiler_Model_Profile[]
31
  */
32
+ protected $children = [];
33
 
34
  /**
35
  * Constructor.
202
  */
203
  public function setChildren(array $children)
204
  {
205
+ $this->children = [];
206
  foreach ($children as $child) {
207
  $this->addChild($child);
208
  }
254
  */
255
  public function setCollectors(array $collectors)
256
  {
257
+ $this->collectors = [];
258
  foreach ($collectors as $collector) {
259
  $this->addCollector($collector);
260
  }
284
 
285
  public function __sleep()
286
  {
287
+ return ['token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode', 'collectTime'];
288
  }
289
  }
app/code/community/Ecocode/Profiler/Model/Profiler.php CHANGED
@@ -49,6 +49,12 @@ class Ecocode_Profiler_Model_Profiler
49
  return $this->enabled;
50
  }
51
 
 
 
 
 
 
 
52
 
53
  public function getDataCollectors()
54
  {
49
  return $this->enabled;
50
  }
51
 
52
+ public function getDataCollector($name)
53
+ {
54
+ $collectors = $this->getDataCollectors();
55
+
56
+ return isset($collectors[$name]) ? $collectors[$name] : false;
57
+ }
58
 
59
  public function getDataCollectors()
60
  {
app/code/community/Ecocode/Profiler/Model/Profiler/FileStorage.php CHANGED
@@ -147,8 +147,8 @@ class Ecocode_Profiler_Model_Profiler_FileStorage
147
  $data = [
148
  'token' => $profile->getToken(),
149
  'parent' => $profile->getParentToken(),
150
- 'children' => array_map(function (Ecocode_Profiler_Model_Profile $p) {
151
- return $p->getToken();
152
  }, $profile->getChildren()),
153
  'data' => $profile->getCollectors(),
154
  'ip' => $profile->getIp(),
147
  $data = [
148
  'token' => $profile->getToken(),
149
  'parent' => $profile->getParentToken(),
150
+ 'children' => array_map(function (Ecocode_Profiler_Model_Profile $profile) {
151
+ return $profile->getToken();
152
  }, $profile->getChildren()),
153
  'data' => $profile->getCollectors(),
154
  'ip' => $profile->getIp(),
app/code/community/Ecocode/Profiler/Model/Session.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Ecocode_Profiler_Model_Profiler_Session
5
+ */
6
+ class Ecocode_Profiler_Model_Session
7
+ extends Mage_Core_Model_Session_Abstract
8
+ {
9
+ public function __construct($data = [])
10
+ {
11
+ $name = isset($data['name']) ? $data['name'] : null;
12
+ $this->init('eco_profiler', $name);
13
+ }
14
+ }
app/code/community/Ecocode/Profiler/Tests/Dev/Controller/AbstractControllerTest.php DELETED
@@ -1,70 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class Ecocode_Profiler_AbstractController
5
- */
6
- class Ecocode_Profiler_Tests_Dev_Controller_AbstractControllerTest
7
- extends TestHelper
8
- {
9
- protected function tearDown()
10
- {
11
- //reset mage as we did some config changes
12
- $this->resetMage();
13
- Mage::getConfig();
14
- }
15
-
16
-
17
- /**
18
- * @expectedException RuntimeException
19
- * @expectExceptionMessageRegExp ^You are not allowed to access this file
20
- */
21
- public function testAccessDenied()
22
- {
23
- $request = new Mage_Core_Controller_Request_Http();
24
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
25
- $controller = $this->getMockBuilder('Ecocode_Profiler_Controller_AbstractController')
26
- ->setMethods(['getApp'])
27
- ->setConstructorArgs([$request, $response])
28
- ->getMock();
29
-
30
- $app = new MageOriginal();
31
- $controller->method('getApp')
32
- ->willReturn($app);
33
-
34
- /** @var Ecocode_Profiler_Controller_AbstractController $controller */
35
- $controller->preDispatch();
36
- }
37
-
38
- public function testAccessAllow()
39
- {
40
- $request = new Mage_Core_Controller_Request_Http();
41
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
42
- $controller = $this->getMockBuilder('Ecocode_Profiler_Controller_AbstractController')
43
- ->setMethods(['getApp', '_rewrite'])
44
- ->setConstructorArgs([$request, $response])
45
- ->getMock();
46
-
47
- $app = new Ecocode_Profiler_Model_AppDev();
48
- $app->init('', 'store');
49
- $controller->method('getApp')
50
- ->willReturn($app);
51
-
52
-
53
- $controller->expects($this->once())
54
- ->method('_rewrite')
55
- ->willReturn(true);
56
-
57
- /** @var Ecocode_Profiler_Controller_AbstractController $controller */
58
- $controller->preDispatch();
59
- $this->assertConfigValue(
60
- $app->getConfig(),
61
- 'disabled',
62
- 'frontend/events/core_block_abstract_to_html_before/observers/ecocode_profiler_context/type'
63
- );
64
- }
65
-
66
- protected function assertConfigValue(Mage_Core_Model_Config $config, $expectValue, $configPath)
67
- {
68
- $this->assertEquals($expectValue, $config->getNode($configPath));
69
- }
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/DevModeTest.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_DevModeTest
4
- extends TestHelper
5
- {
6
-
7
-
8
- public function testDisabledInProduction()
9
- {
10
- $app = Mage::app();
11
-
12
- $this->assertInstanceOf(
13
- 'Ecocode_Profiler_Model_AppDev',
14
- $app
15
- );
16
- }
17
-
18
- public function testCollectorsNotLoaded()
19
- {
20
- $app = Mage::app();
21
-
22
- $value = $app->getConfig()->getNode('ecocode/profiler');
23
- $this->assertNotFalse($value);
24
- }
25
-
26
- public function testModelsNotLoaded()
27
- {
28
- $app = Mage::app();
29
-
30
- $value = $app->getConfig()->getNode('global/models/ecocode_profiler');
31
- $this->assertNotFalse($value);
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Fixtures/DummyCacheBackend.php DELETED
@@ -1,7 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Fixtures_DummyCacheBackend
4
- extends Zend_Cache_Backend
5
- {
6
- protected $_options = ['test_option' => 0];
7
- }
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Fixtures/ResponseHttp.php DELETED
@@ -1,10 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp
4
- extends Mage_Core_Controller_Response_Http
5
- {
6
- public function canSendHeaders($throw = true)
7
- {
8
- return true;
9
- }
10
- }
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Helper/CodeTest.php DELETED
@@ -1,55 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Helper_CodeTest
4
- extends TestHelper
5
- {
6
- /**
7
- * @var Ecocode_Profiler_Helper_Code
8
- */
9
- private $helper;
10
-
11
- protected function setUp()
12
- {
13
- $this->helper = new Ecocode_Profiler_Helper_Code('txmt://open?url=file://%f&line=%l', '/root', 'UTF-8');
14
- }
15
-
16
- public function testFormatFile()
17
- {
18
- $expected = sprintf('<a href="txmt://open?url=file://%s&amp;line=25" title="Click to open this file" class="file_link">%s at line 25</a>', __FILE__, __FILE__);
19
- $this->assertEquals($expected, $this->helper->formatFile(__FILE__, 25));
20
- }
21
-
22
- /**
23
- * @dataProvider getClassNameProvider
24
- */
25
- public function testGettingClassAbbreviation($class, $abbr)
26
- {
27
- $this->assertEquals($this->helper->abbrClass($class), $abbr);
28
- }
29
-
30
- /**
31
- * @dataProvider getMethodNameProvider
32
- */
33
- public function testGettingMethodAbbreviation($method, $abbr)
34
- {
35
- $this->assertEquals($this->helper->abbrMethod($method), $abbr);
36
- }
37
-
38
- public function getClassNameProvider()
39
- {
40
- return array(
41
- array('F\Q\N\Foo', '<abbr title="F\Q\N\Foo">Foo</abbr>'),
42
- array('Bare', '<abbr title="Bare">Bare</abbr>'),
43
- );
44
- }
45
-
46
- public function getMethodNameProvider()
47
- {
48
- return array(
49
- array('F\Q\N\Foo::Method', '<abbr title="F\Q\N\Foo">Foo</abbr>::Method()'),
50
- array('Bare::Method', '<abbr title="Bare">Bare</abbr>::Method()'),
51
- array('Closure', '<abbr title="Closure">Closure</abbr>'),
52
- array('Method', '<abbr title="Method">Method</abbr>()'),
53
- );
54
- }
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Helper/ContextTest.php DELETED
@@ -1,136 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Helper_ContextTest
4
- extends TestHelper
5
- {
6
- public function testInit()
7
- {
8
- $helper = $this->getNewHelper();
9
-
10
- $current = $helper->getCurrent();
11
-
12
- $this->assertEquals('unknown', $current->getKey());
13
- $this->assertEquals(0, $current->getParentId());
14
- $this->assertCount(1, $helper->getList());
15
- }
16
-
17
- public function testCurrentId()
18
- {
19
- $helper = $this->getNewHelper();
20
- $current = $helper->getCurrent();
21
- $this->assertEquals($current->getId(), $helper->getCurrentId());
22
- $helper->close($current);
23
-
24
- $this->assertNull($helper->getCurrentId());
25
- }
26
-
27
- public function testOpen()
28
- {
29
- $helper = $this->getNewHelper();
30
-
31
- $context = new Ecocode_Profiler_Model_Context('test-context');
32
-
33
- $this->assertNotEquals($context, $helper->getCurrent());
34
- $helper->open($context);
35
- $this->assertEquals($context, $helper->getCurrent());
36
- }
37
-
38
- public function testClose()
39
- {
40
- $helper = $this->getNewHelper();
41
-
42
- $context = new Ecocode_Profiler_Model_Context('test-context');
43
-
44
- $helper->open($context);
45
- $this->assertCount(2, $helper->getStack());
46
- $helper->close($context);
47
- $this->assertCount(1, $helper->getStack());
48
- }
49
-
50
- /**
51
- * @expectedException RuntimeException
52
- * @expectedExceptionMessage unable to close unknown context
53
- */
54
- public function testCloseInvalid()
55
- {
56
- $helper = $this->getNewHelper();
57
-
58
- $context = new Ecocode_Profiler_Model_Context('test-context');
59
-
60
- $helper->close($context);
61
- }
62
-
63
- public function testStacking()
64
- {
65
- $helper = $this->getNewHelper();
66
- $rootContext = $helper->getCurrent();
67
- $context1 = new Ecocode_Profiler_Model_Context('test-context-1');
68
- $context2 = new Ecocode_Profiler_Model_Context('test-context-2');
69
-
70
- $helper->open($context1);
71
- $this->assertCount(2, $helper->getStack());
72
- $helper->open($context2);
73
- $this->assertCount(3, $helper->getStack());
74
- $this->assertEquals(
75
- [$rootContext->getId(), $context1->getId(), $context2->getId()],
76
- $this->getStackIds($helper)
77
- );
78
-
79
- $helper->close($context2);
80
- $this->assertEquals(
81
- [$rootContext->getId(), $context1->getId()],
82
- $this->getStackIds($helper)
83
- );
84
-
85
- }
86
-
87
- public function testGetContextById()
88
- {
89
- $helper = $this->getNewHelper();
90
-
91
- $context = new Ecocode_Profiler_Model_Context('test-context');
92
- $profile = new Ecocode_Profiler_Model_Profile('xxx');
93
- $contextCollector = new Ecocode_Profiler_Model_Collector_ContextDataCollector();
94
-
95
- $profile->addCollector($contextCollector);
96
- $helper->open($context);
97
-
98
- $dataProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_ContextDataCollector', 'data');
99
- $dataProperty->setAccessible(true);
100
- $dataProperty->setValue($contextCollector, ['list' => $helper->getList()]);
101
-
102
- $mock = $this
103
- ->getMockBuilder('Ecocode_Profiler_Helper_Context')
104
- ->setMethods(['getCurrentProfile'])
105
- ->getMock();
106
-
107
- $mock->method('getCurrentProfile')
108
- ->willReturn($profile);
109
-
110
- /** @var Ecocode_Profiler_Helper_Context $loadedContext */
111
- $loadedContext = $mock->getContextById($context->getId());
112
- $this->assertEquals(
113
- $context,
114
- $loadedContext
115
- );
116
- }
117
-
118
-
119
- /**
120
- * @return Ecocode_Profiler_Helper_Context
121
- */
122
- protected function getNewHelper()
123
- {
124
- return new Ecocode_Profiler_Helper_Context();
125
- }
126
-
127
- protected function getStackIds(Ecocode_Profiler_Helper_Context $helper)
128
- {
129
- $ids = [];
130
- foreach ($helper->getStack() as $context) {
131
- /** @var Ecocode_Profiler_Model_ContextInterface $context */
132
- $ids[] = $context->getId();
133
- }
134
- return $ids;
135
- }
136
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Helper/DataTest.php DELETED
@@ -1,94 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Helper_DataTest
4
- extends TestHelper
5
- {
6
- public function testGetClassGroup()
7
- {
8
- $classGroup = 'catalog/category';
9
- $class = Mage::getModel($classGroup);
10
-
11
- $helper = $this->getNewHelper();
12
-
13
- $this->assertEquals(
14
- $classGroup,
15
- $helper->getClassGroup($class)
16
- );
17
- }
18
-
19
- public function testUnknownGetClassGroup()
20
- {
21
- $classGroup = 'catalog/xxx';
22
- $class = Mage::getModel($classGroup);
23
-
24
- $helper = $this->getNewHelper();
25
-
26
- $this->assertEquals(
27
- 'unknown',
28
- $helper->getClassGroup($class)
29
- );
30
- }
31
-
32
- public function testGetCollectorUrl()
33
- {
34
- $helper = $this->getNewHelper();
35
- $collector = new Ecocode_Profiler_Model_Collector_MysqlDataCollector();
36
- $token = 'xxx';
37
- $collectorName = $collector->getName();
38
-
39
- $url = $helper->getCollectorUrl($token, $collector);
40
- $url = str_replace(Mage::getBaseUrl(), '', $url);
41
-
42
- $this->assertEquals(
43
- sprintf('_profiler/index/panel/eco_token/%s/panel/%s/', $token, $collectorName),
44
- $url
45
- );
46
- }
47
-
48
-
49
- public function testCleanBacktraceBase()
50
- {
51
- $helper = $this->getNewHelper();
52
- $backtrace = [
53
- ['test' => 'asd', 'function' => 'test'],
54
- ['class' => 'Test_Class', 'function' => 'asd'],
55
- ['class' => 'Test_Class2', 'function' => 'asd'],
56
- ];
57
-
58
- //test empty error handling
59
- $this->assertCount(0, $helper->cleanBacktrace([]));
60
-
61
- $this->assertCount(2, $helper->cleanBacktrace($backtrace));
62
- $this->assertCount(1, $helper->cleanBacktrace($backtrace, ['Test_Class::asd']));
63
- }
64
-
65
- public function testCleanBacktraceInstanceOf()
66
- {
67
- $helper = $this->getNewHelper();
68
- $backtrace = [
69
- ['test' => 'asd', 'function' => 'test'],
70
- ['class' => 'Mage_Catalog_Model_Product', 'function' => 'asd'],
71
- ['class' => 'Ecocode_Profiler_Helper_Data', 'function' => 'asd'],
72
- ['class' => 'Mage_Catalog_Model_Product', 'function' => 'asd']
73
- ];
74
-
75
- foreach ($backtrace as &$trace) {
76
- if (isset($trace['class'])) {
77
- $trace['object'] = $this->getMockBuilder($trace['class'])->disableOriginalConstructor()->getMock();
78
- }
79
- }
80
-
81
- $this->assertCount(3, $helper->cleanBacktrace($backtrace));
82
- $this->assertCount(2, $helper->cleanBacktrace($backtrace, [], ['Varien_Object']));
83
- $this->assertCount(0, $helper->cleanBacktrace($backtrace, [], ['Varien_Object', 'Ecocode_Profiler_Helper_Data']));
84
- }
85
-
86
- /**
87
- * @return Ecocode_Profiler_Helper_Data
88
- */
89
- protected function getNewHelper()
90
- {
91
- return new Ecocode_Profiler_Helper_Data();
92
- }
93
-
94
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Helper/RewriteTest.php DELETED
@@ -1,124 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Helper_RewriteTest
4
- extends TestHelper
5
- {
6
-
7
- /**
8
- * Magento doesn't have any conflicts out of the box, so we need to fake one
9
- */
10
- public function testLoadRewrites()
11
- {
12
- $helperMock = $this->getMockBuilder('Ecocode_Profiler_Helper_Rewrite')
13
- ->setMethods(['getModules', 'getModuleConfigXml'])
14
- ->getMock();
15
-
16
- $modelBaseConfig = new Mage_Core_Model_Config_Element('<data><active>true</active></data>');
17
- $modelDisabledBaseConfig = new Mage_Core_Model_Config_Element('<data><active>false</active></data>');
18
- $modelEtcConfig = new Mage_Core_Model_Config_Element('<config>
19
- <global>
20
- <models>
21
- <core_mysql4>
22
- <rewrite>
23
- <session>XXX_REWRITE</session>
24
- </rewrite>
25
- </core_mysql4>
26
- </models>
27
- </global>
28
- </config>');
29
-
30
- $helperMock
31
- ->expects($this->any())
32
- ->method('getModules')
33
- ->will($this->returnValue([
34
- 'test' => $modelBaseConfig,
35
- 'test2' => $modelDisabledBaseConfig,
36
- ]));
37
-
38
- $helperMock
39
- ->expects($this->at(0))
40
- ->method('getModuleConfigXml')
41
- ->willReturn(false);
42
-
43
- $helperMock
44
- ->expects($this->at(1))
45
- ->method('getModuleConfigXml')
46
- ->with($this->equalTo('test'), $this->equalTo('config.xml'))
47
- ->will($this->returnValue($modelEtcConfig));
48
-
49
- /** @var Ecocode_Profiler_Helper_Rewrite $helperMock */
50
- $result = $helperMock->loadRewrites();
51
- $this->assertEquals(5, count($result, COUNT_RECURSIVE));
52
- }
53
-
54
- /**
55
- * Magento doesn't have any conflicts out of the box, so we need to fake one
56
- */
57
- public function testExecuteConflict()
58
- {
59
- $rewrites = [
60
- 'blocks' => [
61
- 'n98/mock_conflict' => [
62
- 'Mage_Customer_Block_Account',
63
- 'Mage_Tag_Block_All',
64
- ]
65
- ],
66
- 'helpers' => [
67
- 'n98/mock_conflict' => [
68
- 'Mage_Catalog_Helper_Data',
69
- 'Mage_Sales_Helper_Data',
70
- ]
71
- ],
72
- 'models' => [
73
- 'n98/mock_conflict' => [
74
- 'Mage_Catalog_Model_Product',
75
- 'Mage_Sales_Model_Order',
76
- ]
77
- ]
78
- ];
79
- $helper = $this->getHelperWithMockLoadRewrites($rewrites);
80
- $result = $helper->getRewriteConflicts();
81
- $this->assertCount(3, $result);
82
- }
83
-
84
- /**
85
- * This is made to look like a conflict (2 rewrites for the same class) but
86
- * because Bundle extends Catalog, it's valid. Note that we're implying
87
- * Bundle depends on Catalog by passing it as the second value in the array.
88
- */
89
- public function testExecuteConflictFalsePositive()
90
- {
91
- $rewrites = [
92
- 'blocks' => [
93
- 'n98/mock_conflict' => [
94
- 'Mage_Catalog_Block_Product_Price',
95
- 'Mage_Bundle_Block_Catalog_Product_Price',
96
- ]
97
- ]
98
- ];
99
- $helper = $this->getHelperWithMockLoadRewrites($rewrites);
100
- $result = $helper->getRewriteConflicts();
101
- $this->assertCount(0, $result);
102
- }
103
-
104
- /**
105
- * Mock the ConflictsCommand and change the return value of loadRewrites()
106
- * to the given argument
107
- *
108
- * @param array $return
109
- * @return Ecocode_Profiler_Helper_Rewrite
110
- */
111
- private function getHelperWithMockLoadRewrites(array $return)
112
- {
113
- $helperMock = $this->getMockBuilder('Ecocode_Profiler_Helper_Rewrite')
114
- ->setMethods(['loadRewrites'])
115
- ->getMock();
116
-
117
- $helperMock
118
- ->expects($this->any())
119
- ->method('loadRewrites')
120
- ->will($this->returnValue($return));
121
-
122
- return $helperMock;
123
- }
124
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Helper/SqlTest.php DELETED
@@ -1,56 +0,0 @@
1
- <?php
2
-
3
-
4
- class Ecocode_Profiler_Tests_Dev_Helper_SqlTest extends \PHPUnit_Framework_TestCase
5
- {
6
- /**
7
- * @var Ecocode_Profiler_Helper_Sql
8
- */
9
- private $sql;
10
-
11
- protected function setUp()
12
- {
13
- $this->sql = new Ecocode_Profiler_Helper_Sql();
14
- }
15
-
16
- public function testReplaceQueryParametersWithPostgresCasting()
17
- {
18
- $query = 'a=? OR (1)::string OR b=?';
19
- $parameters = [1, 2];
20
- $result = $this->sql->replaceQueryParameters($query, $parameters);
21
- $this->assertEquals('a=1 OR (1)::string OR b=2', $result);
22
- }
23
-
24
- public function testReplaceQueryParametersWithStartingIndexAtOne()
25
- {
26
- $query = 'a=? OR b=?';
27
- $parameters = [
28
- 1 => 1,
29
- 2 => 2
30
- ];
31
- $result = $this->sql->replaceQueryParameters($query, $parameters);
32
- $this->assertEquals('a=1 OR b=2', $result);
33
- }
34
-
35
- public function testReplaceQueryParameters()
36
- {
37
- $query = 'a=? OR b=?';
38
- $parameters = [
39
- 1,
40
- 2
41
- ];
42
- $result = $this->sql->replaceQueryParameters($query, $parameters);
43
- $this->assertEquals('a=1 OR b=2', $result);
44
- }
45
-
46
- public function testReplaceQueryParametersWithNamedIndex()
47
- {
48
- $query = 'a=:a OR b=:b';
49
- $parameters = [
50
- 'a' => 1,
51
- 'b' => 2
52
- ];
53
- $result = $this->sql->replaceQueryParameters($query, $parameters);
54
- $this->assertEquals('a=1 OR b=2', $result);
55
- }
56
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Helper/ValueExporterTest.php DELETED
@@ -1,60 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Helper_ValueExporterTest
4
- extends TestHelper
5
- {
6
- /**
7
- * @var Ecocode_Profiler_Helper_ValueExporter
8
- */
9
- private $valueExporter;
10
-
11
- protected function setUp()
12
- {
13
- $this->valueExporter = new Ecocode_Profiler_Helper_ValueExporter();
14
- }
15
-
16
- public function exportValueDataProvider()
17
- {
18
- $stream = fopen('php://memory', 'w');
19
- return [
20
- [new Varien_Object(), 'Object(Varien_Object)'],
21
- [[new Varien_Object(), new Varien_Object()], '[0 => Object(Varien_Object), 1 => Object(Varien_Object)]'],
22
- [[1, 2], '[0 => 1, 1 => 2]'],
23
- [[1 => ['a', 'b'], []], "[\n 1 => [\n 0 => a, \n 1 => b\n ], \n 2 => []\n]"],
24
- [[null, true, false], '[0 => null, 1 => true, 2 => false]'],
25
- [$stream, sprintf('Resource(stream#%d)', $stream)],
26
- [[str_repeat('x', 100)], "[\n 0 => " . str_repeat('x', 100) . "\n]"]
27
- ];
28
- }
29
-
30
- /**
31
- * @dataProvider exportValueDataProvider
32
- * @param $value
33
- * @param $expectValue
34
- */
35
- public function testExportValue($value, $expectValue)
36
- {
37
- $value = $this->valueExporter->exportValue($value);
38
- $this->assertEquals($expectValue, $value);
39
- }
40
-
41
- public function testDateTime()
42
- {
43
- $dateTime = new \DateTime('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
44
- $this->assertSame('Object(DateTime) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
45
- }
46
-
47
- public function testDateTimeImmutable()
48
- {
49
- $dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
50
- $this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
51
- }
52
-
53
- public function testIncompleteClass()
54
- {
55
- $foo = new \__PHP_Incomplete_Class();
56
- $array = new \ArrayObject($foo);
57
- $array['__PHP_Incomplete_Class_Name'] = 'AppBundle/Foo';
58
- $this->assertSame('__PHP_Incomplete_Class(AppBundle/Foo)', $this->valueExporter->exportValue($foo));
59
- }
60
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/CacheDataCollectorTest.php DELETED
@@ -1,89 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_CacheDataCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function testCollect()
8
- {
9
- $collector = $this->getMockedCollector();
10
-
11
- $collector->collect(
12
- new Mage_Core_Controller_Request_Http(),
13
- new Mage_Core_Controller_Response_Http()
14
- );
15
-
16
- $expectCacheList = json_decode('[{"id":"config","cache_type":"Configuration","description":"System(config.xml, local.xml) and modules configuration files(config.xml).","tags":"CONFIG","status":1},{"id":"layout","cache_type":"Layouts","description":"Layout building instructions.","tags":"LAYOUT_GENERAL_CACHE_TAG","status":1},{"id":"block_html","cache_type":"Blocks HTML output","description":"Page blocks HTML.","tags":"BLOCK_HTML","status":1},{"id":"translate","cache_type":"Translations","description":"Translation files.","tags":"TRANSLATE","status":1},{"id":"collections","cache_type":"Collections Data","description":"Collection data files.","tags":"COLLECTION_DATA","status":1},{"id":"eav","cache_type":"EAV types and attributes","description":"Entity types declaration cache.","tags":"EAV","status":1},{"id":"config_api","cache_type":"Web Services Configuration","description":"Web Services definition files (api.xml).","tags":"CONFIG_API","status":1},{"id":"config_api2","cache_type":"Web Services Configuration","description":"Web Services definition files (api2.xml).","tags":"CONFIG_API2","status":1}]', true);
17
-
18
- $this->assertEquals('Ecocode_Profiler_Tests_Dev_Fixtures_DummyCacheBackend', $collector->getBackendName());
19
- $this->assertEquals(['test_option' => 1], $collector->getBackendOptions());
20
- $this->assertEquals($expectCacheList, $collector->getCacheList());
21
- $this->assertEmpty($collector->getCacheCalls());
22
- }
23
-
24
- public function testLateCollect()
25
- {
26
- $logs = [
27
- ['action' => 'clear', 'id' => 'unknown', 'time' => 0.001],
28
- ['action' => 'load', 'id' => 'core_cache_options1', 'hit' => true, 'time' => 0.005],
29
- ['action' => 'load', 'id' => 'core_cache_options2', 'hit' => true, 'time' => 0.005],
30
- ['action' => 'load', 'id' => 'core_cache_options_miss1', 'hit' => false, 'time' => 0.005],
31
- ['action' => 'load', 'id' => 'core_cache_options_miss2', 'hit' => false, 'time' => 0.005],
32
- ['action' => 'save', 'id' => 'config_global_admin', 'tags' => ['CONFIG'], 'life_time' => null, 'time' => 0.005],
33
- ];
34
-
35
- $collector = $this->getMockedCollector([], $logs);
36
-
37
-
38
- $collector->lateCollect();
39
-
40
- $this->assertEquals([
41
- 'total' => 6,
42
- 'hit' => 2,
43
- 'miss' => 2,
44
- 'save' => 1,
45
- ], $collector->getStats());
46
-
47
- $this->assertEquals(6, $collector->getStats('total'));
48
- $this->assertEquals(0.026, $collector->getTotalTime());
49
- }
50
-
51
- public function getMockedCollector($cacheTypes = [], $log = [])
52
- {
53
- $cacheBackend = new Ecocode_Profiler_Tests_Dev_Fixtures_DummyCacheBackend(['test_option' => 1]);
54
-
55
- $cacheMock = $this->getMockBuilder('Ecocode_Profiler_Model_Core_Cache')
56
- ->setMethods(['getTypes', 'getBackend', 'getLog'])
57
- ->getMock();
58
-
59
- $cacheTypes = $cacheTypes ? $cacheTypes : json_decode('[{"id":"config","cache_type":"Configuration","description":"System(config.xml, local.xml) and modules configuration files(config.xml).","tags":"CONFIG","status":1},{"id":"layout","cache_type":"Layouts","description":"Layout building instructions.","tags":"LAYOUT_GENERAL_CACHE_TAG","status":1},{"id":"block_html","cache_type":"Blocks HTML output","description":"Page blocks HTML.","tags":"BLOCK_HTML","status":1},{"id":"translate","cache_type":"Translations","description":"Translation files.","tags":"TRANSLATE","status":1},{"id":"collections","cache_type":"Collections Data","description":"Collection data files.","tags":"COLLECTION_DATA","status":1},{"id":"eav","cache_type":"EAV types and attributes","description":"Entity types declaration cache.","tags":"EAV","status":1},{"id":"config_api","cache_type":"Web Services Configuration","description":"Web Services definition files (api.xml).","tags":"CONFIG_API","status":1},{"id":"config_api2","cache_type":"Web Services Configuration","description":"Web Services definition files (api2.xml).","tags":"CONFIG_API2","status":1}]', true);
60
- $collectorMock = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_CacheDataCollector')
61
- ->setMethods(['getCacheInstance', 'getCache'])
62
- ->getMock();
63
-
64
- $types = [];
65
- foreach ($cacheTypes as $typeData) {
66
- $id = $typeData['id'];
67
- $types[$id] = new Varien_Object($typeData);
68
- }
69
-
70
- $cacheMock
71
- ->method('getTypes')
72
- ->willReturn($types);
73
-
74
- $cacheMock
75
- ->method('getBackend')
76
- ->willReturn($cacheBackend);
77
-
78
- $cacheMock
79
- ->method('getLog')
80
- ->willReturn($log);
81
-
82
-
83
- $collectorMock->method('getCacheInstance')->willReturn($cacheMock);
84
- $collectorMock->method('getCache')->willReturn($cacheMock);
85
-
86
-
87
- return $collectorMock;
88
- }
89
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/ConfigCollectorTest.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_ConfigCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function testCollect()
8
- {
9
- $token = 'XXX';
10
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
11
- $response->setHeader('X-Debug-Token', $token);
12
- $collector = new Ecocode_Profiler_Model_Collector_ConfigDataCollector();
13
-
14
- Mage::app()->setCurrentStore('admin');
15
- $collector->collect(
16
- new Mage_Core_Controller_Request_Http(),
17
- $response
18
- );
19
-
20
-
21
- $this->assertEquals(0, $collector->getStoreId());
22
- $this->assertEquals('admin', $collector->getStoreCode());
23
- $this->assertEquals('Admin', $collector->getStoreName());
24
-
25
- $this->assertEquals(0, $collector->getWebsiteId());
26
- $this->assertEquals('admin', $collector->getWebsiteCode());
27
- $this->assertEquals('Admin', $collector->getWebsiteName());
28
-
29
- $this->assertEquals($token, $collector->getToken());
30
-
31
- $this->assertFalse($collector->isDeveloperMode());
32
-
33
- $this->assertGreaterThan(1, count($collector->getMagentoModules()));
34
-
35
- $this->assertGreaterThan(1, count($collector->geModulesByState(true)));
36
-
37
- $this->assertNotNull($collector->getMagentoVersion());
38
- $this->assertNotNull($collector->getPhpVersion());
39
-
40
- $this->assertNotNull($collector->hasXDebug());
41
- $this->assertNotNull($collector->hasEAccelerator());
42
- $this->assertNotNull($collector->hasApc());
43
- $this->assertNotNull($collector->hasZendOpcache());
44
- $this->assertNotNull($collector->hasXCache());
45
- $this->assertNotNull($collector->hasWinCache());
46
- $this->assertNotNull($collector->hasAccelerator());
47
- $this->assertNotNull($collector->getSapiName());
48
-
49
-
50
- }
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/ContextDataCollectorTest.php DELETED
@@ -1,54 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_ContextDataCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function testCollect()
8
- {
9
- $collector = new Ecocode_Profiler_Model_Collector_ContextDataCollector();
10
-
11
- $collector->collect(
12
- new Mage_Core_Controller_Request_Http(),
13
- new Mage_Core_Controller_Response_Http()
14
- );
15
-
16
-
17
- $this->assertCount(0, $collector->getList());
18
- }
19
-
20
- public function testLateCollect()
21
- {
22
- $collector = $this->getMockedCollector();
23
-
24
- $this->assertNull($collector->getById('xx'));
25
-
26
- $context = new Ecocode_Profiler_Model_Context('block:test');
27
- $collector->getContextHelper()->open($context);
28
-
29
-
30
- $collector->lateCollect();
31
-
32
- $this->assertCount(2, $collector->getList());
33
-
34
- $this->assertEquals($context, $collector->getById($context->getId()));
35
- }
36
-
37
- /**
38
- * @return Ecocode_Profiler_Model_Collector_ContextDataCollector
39
- */
40
- public function getMockedCollector()
41
- {
42
- $collectorMock = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_ContextDataCollector')
43
- ->setMethods(['getContextHelper'])
44
- ->getMock();
45
-
46
- $contextHelper = new Ecocode_Profiler_Helper_Context();
47
- $collectorMock->method('getContextHelper')
48
- ->willReturn($contextHelper);
49
-
50
-
51
- return $collectorMock;
52
- }
53
-
54
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/CustomerDataCollectorTest.php DELETED
@@ -1,54 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_CustomerDataCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function testCollect()
8
- {
9
- $customer = new Mage_Customer_Model_Customer();
10
- $customer->setData([
11
- 'email' => 'test@test.com',
12
- 'firstname' => 'first',
13
- 'lastname' => 'last'
14
- ]);
15
-
16
- $customerHelper = $this->getMockBuilder('Mage_Customer_Helper_Data')
17
- ->setMethods(['getCustomer', 'isLoggedIn'])
18
- ->getMock();
19
-
20
- $customerHelper->method('getCustomer')
21
- ->willReturn($customer);
22
-
23
- $customerHelper->method('isLoggedIn')
24
- ->willReturn(false);
25
-
26
- /** @var Ecocode_Profiler_Model_Collector_CustomerDataCollector $collector */
27
- $collector = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_CustomerDataCollector')
28
- ->setMethods(['getCustomerHelper'])
29
- ->getMock();
30
-
31
- $collector->method('getCustomerHelper')
32
- ->willReturn($customerHelper);
33
-
34
- $collector->collect(
35
- new Mage_Core_Controller_Request_Http(),
36
- new Mage_Core_Controller_Response_Http()
37
- );
38
-
39
- $this->assertFalse($collector->isLoggedIn());
40
-
41
- $this->assertEquals('test@test.com', $collector->getCustomerEmail());
42
- $this->assertEquals('first last', $collector->getCustomerName());
43
-
44
- $this->assertEquals(1, $collector->getGroupId());
45
- $this->assertEquals('General', $collector->getGroupCode());
46
-
47
-
48
- $this->assertEquals('3', $collector->getTaxClassId());
49
- $this->assertEquals('Retail Customer', $collector->getTaxClassName());
50
- $this->assertEquals('CUSTOMER', $collector->getTaxClassType());
51
-
52
-
53
- }
54
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/EventDataCollectorTest.php DELETED
@@ -1,68 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_EventDataCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function testCollect()
8
- {
9
- $collector = new Ecocode_Profiler_Model_Collector_EventDataCollector();
10
-
11
- $collector->collect(
12
- new Mage_Core_Controller_Request_Http(),
13
- new Mage_Core_Controller_Response_Http()
14
- );
15
-
16
-
17
- $this->assertCount(0, $collector->getCalledListeners());
18
- $this->assertCount(0, $collector->getFiredEvents());
19
- }
20
-
21
- public function testLateCollect()
22
- {
23
- $collector = $this->getMockedCollector();
24
-
25
- $app = new Ecocode_Profiler_Model_AppDev();
26
- $app->init('admin', 'store');
27
- $collector->method('getApp')
28
- ->willReturn($app);
29
-
30
- $preDispatchData = json_decode('{"observers":{"log":{"type":"","model":"log\/visitor","method":"initByRequest","args":[]},"pagecache":{"type":"","model":"pagecache\/observer","method":"processPreDispatch","args":[]}}}', true);
31
- $events = ['global' => ['controller_action_predispatch' => $preDispatchData]];
32
-
33
- $app->dispatchEvent('resource_get_tablename', []);
34
- $app->dispatchEvent('controller_action_predispatch', []);
35
- $app->dispatchEvent('controller_action_predispatch', []);
36
-
37
- $appEvents = new ReflectionProperty('Ecocode_Profiler_Model_AppDev', '_events');
38
- $appEvents->setAccessible(true);
39
- $appEvents->setValue($app, $events);
40
-
41
-
42
- $collector->lateCollect();
43
-
44
- $firedEvents = $collector->getFiredEvents();
45
- $this->assertCount(0, $collector->getCalledListeners());
46
- $this->assertCount(2, $collector->getFiredEvents());
47
-
48
- $data = $firedEvents['controller_action_predispatch'];
49
- $this->assertEquals(2, $data['count']);
50
- $this->assertEquals(2, $data['observer_count']);
51
- $this->assertCount(1, $data['observer']);
52
- $this->assertCount(2, $data['observer']['global']);
53
-
54
- }
55
-
56
- /**
57
- * @return Ecocode_Profiler_Model_Collector_EventDataCollector
58
- */
59
- public function getMockedCollector()
60
- {
61
- $collectorMock = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_EventDataCollector')
62
- ->setMethods(['getApp'])
63
- ->getMock();
64
-
65
-
66
- return $collectorMock;
67
- }
68
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/LayoutDataCollectorTest.php DELETED
@@ -1,221 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_LayoutDataCollectorTest
4
- extends TestHelper
5
- {
6
- public function testBeforeToHtmlNoParent()
7
- {
8
- $start = microtime(true);
9
- $observer = new Varien_Event_Observer();
10
- $event = new Varien_Event();
11
- $testBlock = new Mage_Core_Block_Template();
12
-
13
- $observer->setData('event', $event);
14
- $event->setData('block', $testBlock);
15
-
16
- $collector = new Ecocode_Profiler_Model_Collector_LayoutDataCollector();
17
-
18
- $collector->beforeToHtml($observer);
19
-
20
- $id = $testBlock->getData('profiler_id');
21
- $this->assertNotNull($id);
22
-
23
- $renderLogProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_LayoutDataCollector', 'renderLog');
24
- $renderLogProperty->setAccessible(true);
25
- $log = $renderLogProperty->getValue($collector);
26
-
27
- $this->assertTrue(isset($log[$id]));
28
-
29
- $logEntry = $log[$id];
30
- $this->assertFalse($logEntry['parent_id']);
31
- $this->assertGreaterThan($start, $logEntry['start_render']);
32
- $this->assertEquals(spl_object_hash($testBlock), $logEntry['hash']);
33
- $this->assertCount(0, $logEntry['children']);
34
- $this->assertFalse($logEntry['parent_id']);
35
- }
36
-
37
- public function testBeforeToHtmlWithParent()
38
- {
39
- $observer = new Varien_Event_Observer();
40
- $event = new Varien_Event();
41
- $childBlock = new Mage_Core_Block_Template();
42
- $parentBlock = new Mage_Core_Block_Template();
43
-
44
- $parentBlock->setChild('test-child', $childBlock);
45
-
46
- $observer->setData('event', $event);
47
- $event->setData('block', $parentBlock);
48
-
49
- $collector = new Ecocode_Profiler_Model_Collector_LayoutDataCollector();
50
-
51
- $collector->beforeToHtml($observer);
52
-
53
- $event->setData('block', $childBlock);
54
- $collector->beforeToHtml($observer);
55
-
56
- $parentId = $parentBlock->getData('profiler_id');
57
- $childId = $childBlock->getData('profiler_id');
58
-
59
- $this->assertNotNull($parentId);
60
- $this->assertNotNull($childId);
61
-
62
- $renderLogProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_LayoutDataCollector', 'renderLog');
63
- $renderLogProperty->setAccessible(true);
64
- $log = $renderLogProperty->getValue($collector);
65
-
66
-
67
- $this->assertCount(2, $log);
68
- $this->assertTrue(isset($log[$parentId]));
69
- $this->assertTrue(isset($log[$childId]));
70
-
71
- $parentLogEntry = $log[$parentId];
72
- $childLogEntry = $log[$childId];
73
-
74
- $this->assertFalse($parentLogEntry['parent_id']);
75
- $this->assertEquals($parentId, $childLogEntry['parent_id']);
76
-
77
- $this->assertCount(1, $parentLogEntry['children']);
78
- }
79
-
80
- public function testBeforeToHtmlWidget()
81
- {
82
- $observer = new Varien_Event_Observer();
83
- $event = new Varien_Event();
84
-
85
- $parentBlock = new Mage_Core_Block_Template();
86
- $widgetBlock = new Mage_Catalog_Block_Product_Widget_New();
87
- $widgetChildBlock = new Mage_Core_Block_Template();
88
-
89
- $widgetBlock->setChild('widget-child', $widgetChildBlock);
90
-
91
- $observer->setData('event', $event);
92
-
93
-
94
- $collector = new Ecocode_Profiler_Model_Collector_LayoutDataCollector();
95
-
96
- $blocks = [$parentBlock, $widgetBlock, $widgetChildBlock];
97
-
98
- foreach ($blocks as $block) {
99
- $event->setData('block', $block);
100
- $collector->beforeToHtml($observer);
101
- }
102
-
103
- $renderLogProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_LayoutDataCollector', 'renderLog');
104
- $renderLogProperty->setAccessible(true);
105
- $log = $renderLogProperty->getValue($collector);
106
-
107
-
108
- $this->assertCount(3, $log);
109
-
110
- $this->assertEquals(
111
- $parentBlock->getData('profiler_id'),
112
- $log[$widgetBlock->getData('profiler_id')]['parent_id']
113
- );
114
- }
115
-
116
-
117
- public function testAfterToHtml()
118
- {
119
- $collector = new Ecocode_Profiler_Model_Collector_LayoutDataCollector();
120
-
121
- $observer = new Varien_Event_Observer();
122
- $event = new Varien_Event();
123
- $testBlock = new Mage_Core_Block_Template();
124
-
125
- $testBlock->setTemplate('test.html.php');
126
-
127
- $observer->setData('event', $event);
128
- $event->setData('block', $testBlock);
129
-
130
-
131
- $collector->beforeToHtml($observer);
132
- $collector->afterToHtml($observer);
133
-
134
- $id = $testBlock->getData('profiler_id');
135
- $this->assertNotNull($id);
136
-
137
- $renderLogProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_LayoutDataCollector', 'renderLog');
138
- $renderLogProperty->setAccessible(true);
139
- $log = $renderLogProperty->getValue($collector);
140
-
141
- $blockData = $log[$id];
142
-
143
-
144
- $this->assertNotNull($blockData['stop_render']);
145
- $this->assertEquals($blockData['stop_render'] - $blockData['start_render'], $blockData['render_time_incl']);
146
- $this->assertEquals('test.html.php', $blockData['template']);
147
-
148
- }
149
-
150
-
151
- public function testCollect()
152
- {
153
- /** @var Ecocode_Profiler_Model_Collector_LayoutDataCollector $collector */
154
- $collector = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_LayoutDataCollector')
155
- ->setMethods(['getLayout'])
156
- ->getMock();
157
-
158
- /** @var Mage_Core_Model_Layout $layout */
159
- $layout = new Mage_Core_Model_Layout();
160
-
161
- $collector->method('getLayout')
162
- ->willReturn($layout);
163
-
164
- $observer = new Varien_Event_Observer();
165
- $event = new Varien_Event();
166
-
167
- $childBlock = new Mage_Core_Block_Template();
168
- $parentBlock = new Mage_Core_Block_Template();
169
- $notRenderedBlock = new Mage_Core_Block_Template();
170
-
171
- $layout->getUpdate()->addHandle('default');
172
- $layout->getUpdate()->addHandle('test');
173
- $layout->addBlock($childBlock, 'root');
174
- $layout->addBlock($parentBlock, 'block-2');
175
- $layout->addBlock($notRenderedBlock, 'block-3');
176
-
177
- $layout->addOutputBlock('root');
178
- $blocks = [$parentBlock, $childBlock];
179
-
180
- $observer->setData('event', $event);
181
-
182
- $parentBlock->setChild('test-child', $childBlock);
183
-
184
- foreach ($blocks as $block) {
185
- $event->setData('block', $block);
186
- $collector->beforeToHtml($observer);
187
- }
188
-
189
- foreach (array_reverse($blocks) as $block) {
190
- $event->setData('block', $block);
191
- $collector->afterToHtml($observer);
192
- }
193
-
194
- $collector->collect(
195
- new Mage_Core_Controller_Request_Http(),
196
- new Mage_Core_Controller_Response_Http()
197
- );
198
-
199
- $this->assertCount(2, $collector->getLayoutHandles());
200
- $this->assertEquals(3, $collector->getBlocksCreatedCount());
201
- $this->assertEquals(2, $collector->getBlocksRenderedCount());
202
-
203
- $blocksNotRendered = $collector->getBlocksNotRendered();
204
- $this->assertCount(1, $blocksNotRendered);
205
- $this->assertEquals('block-3', $blocksNotRendered[0]['name']);
206
- $this->assertGreaterThan(0, $collector->getTotalRenderTime());
207
- }
208
-
209
- /**
210
- * @return Ecocode_Profiler_Model_Collector_LayoutDataCollector
211
- */
212
- public function getMockedCollector()
213
- {
214
- $collectorMock = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_LayoutDataCollector')
215
- ->setMethods(['getLayout'])
216
- ->getMock();
217
-
218
-
219
- return $collectorMock;
220
- }
221
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/LogDataCollectorTest.php DELETED
@@ -1,84 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class Ecocode_Profiler_Tests_Dev_Model_Collector_LogDataCollectorTest
5
- *
6
- *
7
- * @requires
8
- */
9
- class Ecocode_Profiler_Tests_Dev_Model_Collector_LogDataCollectorTest
10
- extends TestHelper
11
- {
12
- protected function setUp()
13
- {
14
-
15
- }
16
-
17
-
18
- public function testCollect()
19
- {
20
- /** @var Ecocode_Profiler_Model_Collector_LogDataCollector $collector */
21
- $collector = new Ecocode_Profiler_Model_Collector_LogDataCollector();
22
-
23
-
24
- $collector->collect(
25
- new Mage_Core_Controller_Request_Http(),
26
- new Mage_Core_Controller_Response_Http()
27
- );
28
-
29
- $this->assertEmpty(0, $collector->getLogs());
30
- $this->assertEquals(0, $collector->getLogCount());
31
- }
32
-
33
- public function testLateCollect()
34
- {
35
- if (!class_exists('Monolog\Handler\TestHandler')) {
36
- $this->markTestSkipped(
37
- 'Monolog not installed skipping.'
38
- );
39
- }
40
- $logHandler = new Ecocode_Profiler_Model_Logger_DebugHandler();
41
- $logger = new Ecocode_Profiler_Model_Logger('test', [$logHandler]);
42
-
43
- $collector = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_LogDataCollector')
44
- ->setMethods(['getLogger'])
45
- ->getMock();
46
-
47
- $collector->method('getLogger')
48
- ->willReturn($logger);
49
-
50
-
51
- $logger->debug('test');
52
- $logger->debug('test');
53
-
54
- $context = [
55
- "type" => 8192, "file" => "path/xxxxCategoryController.php", "line" => 43, "level" => 32767
56
- ];
57
- //simulate 3 times same error like in a loop
58
- $logger->info('iconv_set_encoding(): Use of iconv.internal_encoding is deprecated', $context);
59
- $logger->info('iconv_set_encoding(): Use of iconv.internal_encoding is deprecated', $context);
60
- $logger->info('iconv_set_encoding(): Use of iconv.internal_encoding is deprecated', $context);
61
-
62
- $logger->info('another deprecation', ['level' => E_USER_ERROR, 'type' => E_USER_DEPRECATED]);
63
-
64
-
65
- $logger->critical('Fatal Parse Error:', ['level' => E_ALL, 'type' => E_PARSE]);
66
-
67
- /** @var Ecocode_Profiler_Model_Collector_LogDataCollector $collector */
68
- $collector->lateCollect();
69
-
70
-
71
-
72
- $logsByPriorities = $collector->getPriorities();
73
-
74
- $this->assertEquals(2, $logsByPriorities[Ecocode_Profiler_Model_Logger::DEBUG]['count']);
75
- $this->assertEquals(4, $logsByPriorities[Ecocode_Profiler_Model_Logger::INFO]['count']);
76
- $this->assertEquals(1, $logsByPriorities[Ecocode_Profiler_Model_Logger::CRITICAL]['count']);
77
-
78
-
79
- $this->assertEquals(0, $collector->countScreams());
80
- $this->assertEquals(1, $collector->countErrors());
81
- $this->assertEquals(4, $collector->countDeprecations());
82
-
83
- }
84
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/MemoryDataCollectorTest.php DELETED
@@ -1,71 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_MemoryDataCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function collectDataProvider()
8
- {
9
- return [
10
- ['0x1DD5650000', '128134217728'], //hexa //128MB
11
- ['01672531200000', '128134217728'], //octal //128MB
12
- ['-1', -1],
13
- ['1048576K', 1073741824],
14
- ['2048M', 2147483648],
15
- ['2G', 2147483648],
16
- ['1T', 1099511627776]
17
- ];
18
- }
19
-
20
- /**
21
- * @dataProvider collectDataProvider
22
- * @param $limit
23
- * @param $expectedBytes
24
- */
25
- public function testConvertToBytes($limit, $expectedBytes)
26
- {
27
- /** @var Ecocode_Profiler_Model_Collector_MemoryDataCollector $collector */
28
- $collector = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_MemoryDataCollector')
29
- ->setMethods(['getCurrentMemoryLimit'])
30
- ->getMock();
31
-
32
-
33
- $collector->method('getCurrentMemoryLimit')
34
- ->willReturn($limit);
35
-
36
- $collector->collect(
37
- new Mage_Core_Controller_Request_Http(),
38
- new Mage_Core_Controller_Response_Http()
39
- );
40
-
41
- $this->assertEquals($expectedBytes, $collector->getMemoryLimit());
42
- }
43
-
44
- public function testCollect()
45
- {
46
- /** @var Ecocode_Profiler_Model_Collector_MemoryDataCollector $collector */
47
- $collector = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_MemoryDataCollector')
48
- ->setMethods(['getCurrentMemoryUsage'])
49
- ->getMock();
50
-
51
-
52
- $collector->method('getCurrentMemoryUsage')
53
- ->willReturn(100000);
54
-
55
-
56
- $collector->collect(
57
- new Mage_Core_Controller_Request_Http(),
58
- new Mage_Core_Controller_Response_Http()
59
- );
60
-
61
- $this->assertGreaterThan(100000, $collector->getMemory());
62
- }
63
-
64
- public function testLateCollect()
65
- {
66
- $collector = new Ecocode_Profiler_Model_Collector_MemoryDataCollector();
67
-
68
- $collector->lateCollect();
69
- $this->assertGreaterThan(0, $collector->getMemory());
70
- }
71
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/ModelDataCollectorTest.php DELETED
@@ -1,177 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_ModelDataCollectorTest
4
- extends TestHelper
5
- {
6
- public function testCollect()
7
- {
8
- /** @var Ecocode_Profiler_Model_Collector_ModelDataCollector $collector */
9
- $collector = new Ecocode_Profiler_Model_Collector_ModelDataCollector();
10
-
11
- $callLog = [
12
- ['action' => 'load', 'trace_hash' => 'hash-1', 'time' => 10],
13
- ['action' => 'load', 'trace_hash' => 'hash-2', 'time' => 10],
14
- ['action' => 'load', 'trace_hash' => 'hash-3', 'time' => 10],
15
- ['action' => 'load', 'trace_hash' => 'hash-4'],
16
- ['action' => 'load', 'trace_hash' => 'hash-1', 'time' => 10],
17
- ['action' => 'load', 'trace_hash' => 'hash-1', 'time' => 10],
18
- ['action' => 'load', 'trace_hash' => 'hash-2', 'time' => 11],
19
- ['action' => 'save', 'time' => 10],
20
- ['action' => 'delete', 'time' => 10],
21
- ];
22
-
23
- $callLogProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_ModelDataCollector', 'callLog');
24
- $callLogProperty->setAccessible(true);
25
- $callLogProperty->setValue($collector, $callLog);
26
-
27
- $collector->collect(
28
- new Mage_Core_Controller_Request_Http(),
29
- new Mage_Core_Controller_Response_Http()
30
- );
31
-
32
- $this->assertEquals(81, $collector->getTotalTime());
33
- $stats = $collector->getMetric();
34
- $this->assertEquals(5, $collector->getMetric('loop_load'));
35
- $this->assertEquals(7, $stats['load']);
36
- $this->assertEquals(1, $stats['save']);
37
- $this->assertEquals(1, $stats['delete']);
38
-
39
- return $collector;
40
- }
41
-
42
- /**
43
- * @param Ecocode_Profiler_Model_Collector_ModelDataCollector $collector
44
- *
45
- * @depends testCollect
46
- */
47
- public function testGetLoopCalls(Ecocode_Profiler_Model_Collector_ModelDataCollector $collector)
48
- {
49
- $loopCalls = $collector->getLoadLoopCalls();
50
-
51
- $this->assertCount(2, $loopCalls);
52
- $loopCall = reset($loopCalls);
53
-
54
- $this->assertEquals(3, $loopCall['count']);
55
- $this->assertEquals(30, $loopCall['total_time']);
56
- }
57
-
58
- public function testTrackModelLoad()
59
- {
60
- $model = Mage::getModel('catalog/product');
61
- /** @var Ecocode_Profiler_Model_Collector_ModelDataCollector $collector */
62
- $collector = new Ecocode_Profiler_Model_Collector_ModelDataCollector();
63
-
64
-
65
- $collector->trackModelLoad($this->getObserver(['object' => $model, 'time' => 100]));
66
-
67
- $callLogProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_ModelDataCollector', 'callLog');
68
- $callLogProperty->setAccessible(true);
69
-
70
- $callLog = $callLogProperty->getValue($collector);
71
-
72
- $this->assertCount(1, $callLog);
73
-
74
- $callLogItem = reset($callLog);
75
-
76
- $this->assertEquals('load', $callLogItem['action']);
77
- $this->assertEquals('Mage_Catalog_Model_Product', $callLogItem['class']);
78
- $this->assertEquals('catalog/product', $callLogItem['class_group']);
79
- $this->assertEquals('load', $callLogItem['action']);
80
- $this->assertEquals(100, $callLogItem['time']);
81
- $this->assertCount(0, $callLogItem['trace']);
82
-
83
-
84
- }
85
-
86
- public function testTrackModelDelete()
87
- {
88
- $model = Mage::getModel('catalog/product');
89
- $collector = new Ecocode_Profiler_Model_Collector_ModelDataCollector();
90
-
91
- $collector->trackModelDelete($this->getObserver(['object' => $model]));
92
-
93
- $callLogProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_ModelDataCollector', 'callLog');
94
- $callLogProperty->setAccessible(true);
95
-
96
- $callLog = $callLogProperty->getValue($collector);
97
-
98
- $this->assertCount(1, $callLog);
99
-
100
- $callLogItem = reset($callLog);
101
-
102
- $this->assertEquals('delete', $callLogItem['action']);
103
- $this->assertCount(0, $callLogItem['trace']);
104
- }
105
-
106
- public function testTrackModelSave()
107
- {
108
- $model = Mage::getModel('catalog/product');
109
- $collector = new Ecocode_Profiler_Model_Collector_ModelDataCollector();
110
-
111
- $collector->trackModelSave($this->getObserver(['object' => $model]));
112
-
113
- $callLogProperty = new ReflectionProperty('Ecocode_Profiler_Model_Collector_ModelDataCollector', 'callLog');
114
- $callLogProperty->setAccessible(true);
115
-
116
- $callLog = $callLogProperty->getValue($collector);
117
-
118
- $this->assertCount(1, $callLog);
119
-
120
- $callLogItem = reset($callLog);
121
-
122
- $this->assertEquals('save', $callLogItem['action']);
123
- $this->assertCount(0, $callLogItem['trace']);
124
- }
125
-
126
-
127
- public function testCleanBacktrace()
128
- {
129
- $collector = new Ecocode_Profiler_Model_Collector_ModelDataCollector();
130
-
131
- $cleanBacktraceMethod = new ReflectionMethod('Ecocode_Profiler_Model_Collector_ModelDataCollector', 'cleanBacktrace');
132
- $cleanBacktraceMethod->setAccessible(true);
133
-
134
- $trace = json_decode('[{"file":"xdebug:\/\/debug-eval(1) : eval()\'d code","line":1,"function":"getBacktrace","class":"Ecocode_Profiler_Model_Collector_AbstractDataCollector","type":"->"},{"file":"xdebug:\/\/debug-eval","line":1,"function":"eval"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Model\/Collector\/ModelDataCollector.php","line":157,"function":"track","class":"Ecocode_Profiler_Model_Collector_ModelDataCollector","type":"::"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Model\/Collector\/ModelDataCollector.php","line":140,"function":"track","class":"Ecocode_Profiler_Model_Collector_ModelDataCollector","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Model\/Collector\/ModelDataCollector.php","line":123,"function":"trackEvent","class":"Ecocode_Profiler_Model_Collector_ModelDataCollector","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/App.php","line":1338,"function":"trackModelLoad","class":"Ecocode_Profiler_Model_Collector_ModelDataCollector","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Model\/AppDev.php","line":124,"function":"_callObserverMethod","class":"Mage_Core_Model_App","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/App.php","line":1317,"function":"_callObserverMethod","class":"Ecocode_Profiler_Model_AppDev","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Model\/AppDev.php","line":91,"function":"dispatchEvent","class":"Mage_Core_Model_App","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/var\/cache\/Original_Mage_1.0.11-a6f179080788cdb98ede80fce0a470e1.php","line":456,"function":"dispatchEvent","class":"Ecocode_Profiler_Model_AppDev","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/overwrite\/Mage.php","line":102,"function":"dispatchEvent","class":"MageOriginal","type":"::"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/overwrite\/MageCoreModelResourceDbAbstract.php","line":24,"function":"dispatchDebugEvent","class":"Mage","type":"::"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Cms\/Model\/Resource\/Page.php","line":170,"function":"load","class":"Mage_Core_Model_Resource_Db_Abstract","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/Abstract.php","line":225,"function":"load","class":"Mage_Cms_Model_Resource_Page","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Cms\/Model\/Page.php","line":113,"function":"load","class":"Mage_Core_Model_Abstract","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Cms\/Helper\/Page.php","line":74,"function":"load","class":"Mage_Cms_Model_Page","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Cms\/Helper\/Page.php","line":52,"function":"_renderPage","class":"Mage_Cms_Helper_Page","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Cms\/controllers\/IndexController.php","line":45,"function":"renderPage","class":"Mage_Cms_Helper_Page","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Controller\/Varien\/Action.php","line":418,"function":"indexAction","class":"Mage_Cms_IndexController","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Controller\/Varien\/Router\/Standard.php","line":250,"function":"dispatch","class":"Mage_Core_Controller_Varien_Action","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Controller\/Varien\/Front.php","line":172,"function":"match","class":"Mage_Core_Controller_Varien_Router_Standard","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/App.php","line":354,"function":"dispatch","class":"Mage_Core_Controller_Varien_Front","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/var\/cache\/Original_Mage_1.0.11-a6f179080788cdb98ede80fce0a470e1.php","line":692,"function":"run","class":"Mage_Core_Model_App","type":"->"},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/dev.php","line":68,"function":"run","class":"MageOriginal","type":"::"}]', true);
135
- $cleanedTrace = $cleanBacktraceMethod->invoke($collector, $trace);
136
-
137
-
138
- $firstTraceItem = reset($cleanedTrace);
139
- $this->assertCount(12, $cleanedTrace);
140
- $this->assertEquals('load', $firstTraceItem['function']);
141
- $this->assertFalse(isset($firstTraceItem['object']));
142
- $this->assertFalse(isset($firstTraceItem['args']));
143
- $this->assertFalse(isset($firstTraceItem['type']));
144
- }
145
-
146
- public function shouldRemoveBacktraceProvider()
147
- {
148
- return [
149
- [[], true],
150
- [['class' => 'test'], true],
151
- [['class' => 'Mage_Cms_Model_Resource_Page', 'function' => 'load'], true],
152
- [['class' => 'Mage_Cms_Model_Resource_Page', 'function' => '_load'], true],
153
- [false, false],
154
- [['class' => 'Mage_Core_Model_Resource_Db_Abstract', 'function' => '_load'], true],
155
- [['class' => 'Mage_Core_Model_Resource_Db_Abstract', 'function' => 'load'], false],
156
- [['class' => 'Mage_Eav_Model_Entity_Abstract', 'function' => 'load'], false],
157
- ];
158
- }
159
-
160
- /**
161
- * @dataProvider shouldRemoveBacktraceProvider
162
- *
163
- * @param $data
164
- * @param $expect
165
- */
166
- public function testShouldRemoveBacktrace($data, $expect)
167
- {
168
- $collector = new Ecocode_Profiler_Model_Collector_ModelDataCollector();
169
-
170
- $shouldRemoveBacktraceMethod = new ReflectionMethod('Ecocode_Profiler_Model_Collector_ModelDataCollector', 'shouldRemoveBacktrace');
171
- $shouldRemoveBacktraceMethod->setAccessible(true);
172
-
173
- $shouldRemove = $shouldRemoveBacktraceMethod->invoke($collector, $data);
174
-
175
- $this->assertEquals($expect, $shouldRemove);
176
- }
177
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/MysqlDataCollectorTest.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_MysqlDataCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function testBackTrace()
8
- {
9
- $originalTrace = json_decode('[{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Model\/Collector\/MysqlDataCollector.php","line":95,"function":"getBackTrace","class":"Ecocode_Profiler_Model_Collector_MysqlDataCollector","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Model\/Collector\/MysqlDataCollector.php","line":40,"function":"getTrace","class":"Ecocode_Profiler_Model_Collector_MysqlDataCollector","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Db\/Statement\/Pdo\/Mysql.php","line":55,"function":"logQuery","class":"Ecocode_Profiler_Model_Collector_MysqlDataCollector","object":{},"type":"->","args":[{}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/app\/code\/community\/Ecocode\/Profiler\/Db\/Statement\/Pdo\/Mysql.php","line":48,"function":"log","class":"Ecocode_Profiler_Db_Statement_Pdo_Mysql","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Zend\/Db\/Statement.php","line":291,"function":"_execute","class":"Ecocode_Profiler_Db_Statement_Pdo_Mysql","object":{},"type":"->","args":[{":path0":"",":path1":"\/"}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/lib\/Zend\/Db\/Adapter\/Abstract.php","line":479,"function":"execute","class":"Zend_Db_Statement","object":{},"type":"->","args":[{":path0":"",":path1":"\/"}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/lib\/Zend\/Db\/Adapter\/Pdo\/Abstract.php","line":238,"function":"query","class":"Zend_Db_Adapter_Abstract","object":{},"type":"->","args":["SELECT `core_url_rewrite`.* FROM `core_url_rewrite` WHERE (request_path IN (:path0, :path1)) AND (store_id IN(0, 1))",{":path0":"",":path1":"\/"}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/lib\/Varien\/Db\/Adapter\/Pdo\/Mysql.php","line":428,"function":"query","class":"Zend_Db_Adapter_Pdo_Abstract","object":{},"type":"->","args":["SELECT `core_url_rewrite`.* FROM `core_url_rewrite` WHERE (request_path IN (:path0, :path1)) AND (store_id IN(0, 1))",{":path0":"",":path1":"\/"}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/lib\/Zend\/Db\/Adapter\/Abstract.php","line":734,"function":"query","class":"Varien_Db_Adapter_Pdo_Mysql","object":{},"type":"->","args":[{},{"path0":"","path1":"\/"}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/Resource\/Url\/Rewrite.php","line":151,"function":"fetchAll","class":"Zend_Db_Adapter_Abstract","object":{},"type":"->","args":[{},{"path0":"","path1":"\/"}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/Url\/Rewrite.php","line":100,"function":"loadByRequestPath","class":"Mage_Core_Model_Resource_Url_Rewrite","object":{},"type":"->","args":[{},["","\/"]]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/Url\/Rewrite\/Request.php","line":139,"function":"loadByRequestPath","class":"Mage_Core_Model_Url_Rewrite","object":{},"type":"->","args":[["","\/"]]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/Url\/Rewrite\/Request.php","line":116,"function":"_rewriteDb","class":"Mage_Core_Model_Url_Rewrite_Request","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Controller\/Varien\/Front.php","line":165,"function":"rewrite","class":"Mage_Core_Model_Url_Rewrite_Request","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/App.php","line":354,"function":"dispatch","class":"Mage_Core_Controller_Varien_Front","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/var\/cache\/Original_Mage_1.0.11-a6f179080788cdb98ede80fce0a470e1.php","line":692,"function":"run","class":"Mage_Core_Model_App","object":{},"type":"->","args":[{"scope_code":"","scope_type":"store","options":{"cache":{"id_prefix":"dev"},"config_model":"Ecocode_Profiler_Model_Core_Config"}}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/dev.php","line":68,"function":"run","class":"MageOriginal","type":"::","args":["","store",{"cache":{"id_prefix":"dev"},"config_model":"Ecocode_Profiler_Model_Core_Config"}]}]', true);
10
- $expectedTrace = json_decode('[{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/Url\/Rewrite.php","line":100,"function":"loadByRequestPath","class":"Mage_Core_Model_Resource_Url_Rewrite","object":{},"type":"->","args":[{},["","\/"]]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/Url\/Rewrite\/Request.php","line":139,"function":"loadByRequestPath","class":"Mage_Core_Model_Url_Rewrite","object":{},"type":"->","args":[["","\/"]]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/Url\/Rewrite\/Request.php","line":116,"function":"_rewriteDb","class":"Mage_Core_Model_Url_Rewrite_Request","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Controller\/Varien\/Front.php","line":165,"function":"rewrite","class":"Mage_Core_Model_Url_Rewrite_Request","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/app\/code\/core\/Mage\/Core\/Model\/App.php","line":354,"function":"dispatch","class":"Mage_Core_Controller_Varien_Front","object":{},"type":"->","args":[]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/httpdocs\/var\/cache\/Original_Mage_1.0.11-a6f179080788cdb98ede80fce0a470e1.php","line":692,"function":"run","class":"Mage_Core_Model_App","object":{},"type":"->","args":[{"scope_code":"","scope_type":"store","options":{"cache":{"id_prefix":"dev"},"config_model":"Ecocode_Profiler_Model_Core_Config"}}]},{"file":"\/projects\/ecocode\/ecocode_profiler_test\/magento-1.8.1.0\/vendor\/ecocode\/magento_profiler\/dev.php","line":68,"function":"run","class":"MageOriginal","type":"::","args":["","store",{"cache":{"id_prefix":"dev"},"config_model":"Ecocode_Profiler_Model_Core_Config"}]}]', true);
11
-
12
- foreach ($originalTrace as &$trace) {
13
- if (isset($trace['class'])) {
14
- $trace['object'] = $this->getMockBuilder($trace['class'])->disableOriginalConstructor()->getMock();
15
- }
16
- }
17
- $dataCollector = new Ecocode_Profiler_Model_Collector_MysqlDataCollector();
18
-
19
- $cleanedTrace = $dataCollector->cleanBacktrace($originalTrace);
20
-
21
- $this->assertCount(count($expectedTrace), $cleanedTrace);
22
- }
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/RequestDataCollectorTest.php DELETED
@@ -1,158 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_RequestDataCollectorTest
4
- extends TestHelper
5
- {
6
- public function testCollect()
7
- {
8
- $collector = new Ecocode_Profiler_Model_Collector_RequestDataCollector();
9
-
10
-
11
- $request = $this->getMockBuilder('Mage_Core_Controller_Request_Http')
12
- ->setMethods(['getMethod', 'getServer', 'getCookie'])
13
- ->getMock();
14
-
15
- $serverData = [
16
- 'REDIRECT_STATUS' => 200,
17
- 'HTTP_HOST' => 'profiler.test',
18
- 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, sdch',
19
- ];
20
- $cookieData = [
21
- 'frontend' => 'session-key'
22
- ];
23
- $request->method('getMethod')->willReturn('GET');
24
- $request->method('getServer')->willReturn($serverData);
25
- $request->method('getCookie')->willReturn($cookieData);
26
-
27
- $request->setRequestUri('/dev.php/electronics.html');
28
- $request->setBaseUrl('/dev.php');
29
- $request->setPathInfo();
30
-
31
- $request->setRequestUri('/dev.php/catalog/category/view/id/13');
32
- $request->setPathInfo('catalog/category/view/id/13');
33
- $request->setParams(['id' => '13']);
34
- $request->setRouteName('catalog');
35
- $request->setControllerName('category');
36
- $request->setActionName('view');
37
-
38
-
39
- /** @var Mage_Core_Controller_Request_Http $request */
40
-
41
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
42
- $response->setHttpResponseCode(201);
43
- $response->setHeader('content-Type', 'application/json');
44
- $response->setHeader('X-DEBUG-TOKEN', 'XXX');
45
-
46
-
47
- $collector->collect(
48
- $request,
49
- $response
50
- );
51
-
52
- $this->assertEquals('GET', $collector->getMethod());
53
- $this->assertEquals('application/json', $collector->getContentType());
54
- $this->assertEquals(201, $collector->getStatusCode());
55
- $this->assertEquals(Ecocode_Profiler_Model_Collector_RequestDataCollector::$statusTexts[201], $collector->getStatusText());
56
- $this->assertEquals(
57
- ['host' => ['profiler.test'], 'accept-encoding' => ['gzip, deflate, sdch']],
58
- $collector->getRequestHeaders()->all()
59
- );
60
-
61
- $this->assertEquals(
62
- $serverData,
63
- $collector->getRequestServer()->all()
64
- );
65
-
66
- $this->assertEquals(
67
- $cookieData,
68
- $collector->getRequestCookies()->all()
69
- );
70
-
71
- $this->assertEquals('catalog/category/view/id/13', $collector->getPathInfo());
72
- //no post data
73
- $this->assertEmpty($collector->getRequestRequest());
74
-
75
- //no get data
76
- $this->assertEmpty($collector->getRequestQuery());
77
-
78
- $this->assertCount(4, $collector->getController());
79
-
80
- $this->assertInstanceOf('Ecocode_Profiler_Model_Http_ResponseHeaderBag', $collector->getResponseHeaders());
81
-
82
- return $collector;
83
- }
84
-
85
- public function testCollectParameters()
86
- {
87
- $collector = new Ecocode_Profiler_Model_Collector_RequestDataCollector();
88
-
89
-
90
- $request = $this->getMockBuilder('Mage_Core_Controller_Request_Http')
91
- ->setMethods(['getQuery', 'getPost'])
92
- ->getMock();
93
-
94
- $request->method('getQuery')->willReturn(['q' => 'search']);
95
- $request->method('getPost')->willReturn(['key' => 'data']);
96
-
97
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
98
- $collector->collect($request, $response);
99
-
100
- //no post data
101
- $this->assertEquals(['key' => 'data'], $collector->getRequestRequest()->all());
102
-
103
- //no get data
104
- $this->assertEquals(['q' => 'search'], $collector->getRequestQuery()->all());
105
- }
106
-
107
-
108
- public function testParseController()
109
- {
110
- $collector = new Ecocode_Profiler_Model_Collector_RequestDataCollector();
111
-
112
- $controller = new Mage_Core_Controller_Varien_Front();
113
-
114
- $parseControllerMethod = new ReflectionMethod('Ecocode_Profiler_Model_Collector_RequestDataCollector', 'parseController');
115
- $parseControllerMethod->setAccessible(true);
116
-
117
-
118
- $controllerData = $parseControllerMethod->invoke($collector, false);
119
- $this->assertEquals('n/a', $controllerData);
120
-
121
- $controllerData = $parseControllerMethod->invoke($collector, $controller);
122
-
123
- $this->assertEquals('Mage_Core_Controller_Varien_Front', $controllerData['class']);
124
- }
125
-
126
- public function testDetectStatusCode()
127
- {
128
- $collector = new Ecocode_Profiler_Model_Collector_RequestDataCollector();
129
-
130
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
131
- $response->setHttpResponseCode(200);
132
-
133
- $detectStatusCodeMethod = new ReflectionMethod('Ecocode_Profiler_Model_Collector_RequestDataCollector', 'detectStatusCode');
134
- $detectStatusCodeMethod->setAccessible(true);
135
-
136
- $this->assertEquals(200, $detectStatusCodeMethod->invoke($collector, $response));
137
-
138
- //magento does not set the status 100% correct, sometime only the header is present
139
- $response->setHeader('Http/1.1', '404 Not Found');
140
- $this->assertEquals(404, $detectStatusCodeMethod->invoke($collector, $response));
141
- }
142
-
143
- /**
144
- * @depends testCollect
145
- */
146
- public function testCollectRequestAttributes(Ecocode_Profiler_Model_Collector_RequestDataCollector $collector)
147
- {
148
- $this->assertInstanceOf('Ecocode_Profiler_Model_Http_ParameterBag', $collector->getRequestAttributes());
149
- $this->assertEquals('/electronics.html', $collector->getRequestString());
150
- $this->assertEquals('/dev.php/catalog/category/view/id/13', $collector->getRequestUri());
151
- $this->assertEquals('catalog', $collector->getModuleName());
152
- $this->assertEquals('category', $collector->getControllerName());
153
- $this->assertEquals('view', $collector->getActionName());
154
- $this->assertEquals('catalog_category_view', $collector->getRoute());
155
- $this->assertEquals('catalog', $collector->getRouteName());
156
- $this->assertEquals(['id' => '13'], $collector->getRouteParams());
157
- }
158
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/RewriteDataCollectorTest.php DELETED
@@ -1,39 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_RewriteDataCollectorTest
4
- extends TestHelper
5
- {
6
- public function testCollect()
7
- {
8
- $rewriteHelperMock = $this->getMockBuilder('Ecocode_Profiler_Helper_Rewrite')
9
- ->setMethods(['loadRewrites', 'getRewriteConflicts'])
10
- ->getMock();
11
-
12
- //fake a conflict and sample load rewrites
13
- $rewrites = json_decode('{"blocks":[],"helpers":[],"models":{"core_mysql4\/session":["XXX_REWRITE"]}}', true);
14
- $conflicts = json_decode('[{"type":"blocks","class":"n98\/mock_conflict","rewrites":["Mage_Customer_Block_Account","Mage_Tag_Block_All"],"loaded_class":"Mage_N98_Block_Mock_Conflict"}]', true);
15
-
16
- $rewriteHelperMock->method('loadRewrites')->willReturn($rewrites);
17
- $rewriteHelperMock->method('getRewriteConflicts')->willReturn($conflicts);
18
-
19
- /** @var Ecocode_Profiler_Model_Collector_RewriteDataCollector $collector */
20
- $collector = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_RewriteDataCollector')
21
- ->setMethods(['getRewriteHelper'])
22
- ->getMock();
23
-
24
-
25
- $collector->method('getRewriteHelper')->willReturn($rewriteHelperMock);
26
-
27
- $collector->collect(
28
- new Mage_Core_Controller_Request_Http(),
29
- new Mage_Core_Controller_Response_Http()
30
- );
31
-
32
- $rewrites = $collector->getModuleRewrites();
33
- $this->assertCount(0, $rewrites['blocks']);
34
- $this->assertCount(0, $rewrites['helpers']);
35
- $this->assertCount(1, $rewrites['models']);
36
- $this->assertCount(1, $collector->getModuleRewriteConflicts());
37
- $this->assertEquals(1, $collector->getModuleRewriteConflictCount());
38
- }
39
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/TimeDataCollectorTest.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_TimeDataCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function testCollect()
8
- {
9
- /** @var Ecocode_Profiler_Model_Collector_TimeDataCollector $collector */
10
- $collector = new Ecocode_Profiler_Model_Collector_TimeDataCollector();
11
-
12
- $collector->collect(
13
- new Mage_Core_Controller_Request_Http(),
14
- new Mage_Core_Controller_Response_Http()
15
- );
16
-
17
- $this->assertEquals(0, $collector->getTotalTime());
18
- return $collector;
19
- }
20
-
21
- /**
22
- * @depends testCollect
23
- */
24
- public function testLateCollect(Ecocode_Profiler_Model_Collector_TimeDataCollector $collector)
25
- {
26
- $collector->lateCollect();
27
- $this->assertGreaterThan(0, $collector->getTotalTime());
28
- }
29
-
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Collector/TranslationDataCollectorTest.php DELETED
@@ -1,79 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Collector_TranslationDataCollectorTest
4
- extends TestHelper
5
- {
6
-
7
- public function testCollect()
8
- {
9
- $translate = new Mage_Core_Model_Translate();
10
- /** @var Ecocode_Profiler_Model_Collector_TranslationDataCollector $collector */
11
- $collector = $this->getMockBuilder('Ecocode_Profiler_Model_Collector_TranslationDataCollector')
12
- ->setMethods(['getTranslator'])
13
- ->getMock();
14
-
15
- $collector->method('getTranslator')->willReturn($translate);
16
-
17
- $messageLog = [
18
- ['DE_de', 'code-1', 'the-text', 'the-translation', 'translated'],
19
- ['DE_de', 'code-1', 'the-text', 'the-translation', 'translated'],
20
- ['DE_de', 'code-2', 'the-text', 'the-translation', 'missing'],
21
- ['DE_de', 'code-3', 'the-text', 'the-translation', 'invalid'],
22
- ['DE_de', 'with-trace', 'the-text', 'the-translation', 'fallback', [], null, ['trace1' => []]],
23
- ['DE_de', 'with-trace', 'the-text', 'the-translation', 'fallback', [], null, ['trace2' => []]],
24
- ['DE_de', 'multiple-parameters', 'the-text', 'the-translation', 'fallback', ['a' => 'b'], 'catalog'],
25
- ['DE_de', 'multiple-parameters', 'the-text', 'the-translation', 'fallback', ['c' => 'd'], 'catalog']
26
- ];
27
-
28
- $messages = [];
29
- foreach ($messageLog as $message) {
30
- $messages[] = [
31
- 'locale' => $message[0],
32
- 'code' => $message[1],
33
- 'text' => $message[2],
34
- 'translation' => $message[3],
35
- 'state' => $message[4],
36
- 'parameters' => isset($message[5]) ? $message[5] : [],
37
- 'module' => isset($message[6]) ? $message[6] : null,
38
- 'trace' => isset($message[7]) ? $message[7] : [],
39
- ];
40
- }
41
- $messagesProperty = new ReflectionProperty('Mage_Core_Model_Translate', 'messages');
42
- $messagesProperty->setAccessible(true);
43
- $messagesProperty->setValue($translate, $messages);
44
-
45
- $collector->collect(
46
- new Mage_Core_Controller_Request_Http(),
47
- new Mage_Core_Controller_Response_Http()
48
- );
49
-
50
- $translations = $collector->getTranslations();
51
- $this->assertCount(5, $translations);
52
- $this->assertEquals(5, $collector->getTranslationCount());
53
-
54
- $this->assertEquals(2, $translations['code-1']['count']);
55
- $this->assertEquals(1, $translations['code-2']['count']);
56
-
57
- //test stats counts
58
-
59
- //test trace set
60
- $this->assertCount(2, $translations['with-trace']['traces']);
61
-
62
- //test parameters
63
- $this->assertEmpty($translations['code-1']['parameters']);
64
- $this->assertNotEmpty($translations['multiple-parameters']['parameters']);
65
- $this->assertEquals([['a' => 'b'], ['c' => 'd']], $translations['multiple-parameters']['parameters']);
66
-
67
- //getStateCount
68
- $this->assertTrue(is_array($collector->getStateCount()));
69
- $this->assertEquals(1, $collector->getStateCount('translated'));
70
- $this->assertEquals(1, $collector->getStateCount('missing'));
71
- $this->assertEquals(1, $collector->getStateCount('invalid'));
72
- $this->assertEquals(2, $collector->getStateCount('fallback'));
73
-
74
- $this->assertEquals(4, $collector->getNotOkCount());
75
-
76
-
77
- return $collector;
78
- }
79
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Http/HeaderBagTest.php DELETED
@@ -1,192 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * This file is part of the Symfony package.
5
- *
6
- * (c) Fabien Potencier <fabien@symfony.com>
7
- *
8
- * For the full copyright and license information, please view the LICENSE
9
- * file that was distributed with this source code.
10
- */
11
-
12
-
13
- class HeaderBagTest extends \PHPUnit_Framework_TestCase
14
- {
15
- public function testConstructor()
16
- {
17
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'bar'));
18
- $this->assertTrue($bag->has('foo'));
19
- }
20
-
21
- public function testToStringNull()
22
- {
23
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag();
24
- $this->assertEquals('', $bag->__toString());
25
- }
26
-
27
- public function testToStringNotNull()
28
- {
29
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'bar'));
30
- $this->assertEquals("Foo: bar\r\n", $bag->__toString());
31
- }
32
-
33
- public function testKeys()
34
- {
35
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'bar'));
36
- $keys = $bag->keys();
37
- $this->assertEquals('foo', $keys[0]);
38
- }
39
-
40
- public function testGetDate()
41
- {
42
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'Tue, 4 Sep 2012 20:00:00 +0200'));
43
- $headerDate = $bag->getDate('foo');
44
- $this->assertInstanceOf('DateTime', $headerDate);
45
- }
46
-
47
- /**
48
- * @expectedException \RuntimeException
49
- */
50
- public function testGetDateException()
51
- {
52
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'Tue'));
53
- $headerDate = $bag->getDate('foo');
54
- }
55
-
56
- public function testGetCacheControlHeader()
57
- {
58
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag();
59
- $bag->addCacheControlDirective('public', '#a');
60
- $this->assertTrue($bag->hasCacheControlDirective('public'));
61
- $this->assertEquals('#a', $bag->getCacheControlDirective('public'));
62
- }
63
-
64
- public function testAll()
65
- {
66
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'bar'));
67
- $this->assertEquals(array('foo' => array('bar')), $bag->all(), '->all() gets all the input');
68
-
69
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('FOO' => 'BAR'));
70
- $this->assertEquals(array('foo' => array('BAR')), $bag->all(), '->all() gets all the input key are lower case');
71
- }
72
-
73
- public function testReplace()
74
- {
75
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'bar'));
76
-
77
- $bag->replace(array('NOPE' => 'BAR'));
78
- $this->assertEquals(array('nope' => array('BAR')), $bag->all(), '->replace() replaces the input with the argument');
79
- $this->assertFalse($bag->has('foo'), '->replace() overrides previously set the input');
80
- }
81
-
82
- public function testGet()
83
- {
84
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'bar', 'fuzz' => 'bizz'));
85
- $this->assertEquals('bar', $bag->get('foo'), '->get return current value');
86
- $this->assertEquals('bar', $bag->get('FoO'), '->get key in case insensitive');
87
- $this->assertEquals(array('bar'), $bag->get('foo', 'nope', false), '->get return the value as array');
88
-
89
- // defaults
90
- $this->assertNull($bag->get('none'), '->get unknown values returns null');
91
- $this->assertEquals('default', $bag->get('none', 'default'), '->get unknown values returns default');
92
- $this->assertEquals(array('default'), $bag->get('none', 'default', false), '->get unknown values returns default as array');
93
-
94
- $bag->set('foo', 'bor', false);
95
- $this->assertEquals('bar', $bag->get('foo'), '->get return first value');
96
- $this->assertEquals(array('bar', 'bor'), $bag->get('foo', 'nope', false), '->get return all values as array');
97
- }
98
-
99
- public function testSetAssociativeArray()
100
- {
101
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag();
102
- $bag->set('foo', array('bad-assoc-index' => 'value'));
103
- $this->assertSame('value', $bag->get('foo'));
104
- $this->assertEquals(array('value'), $bag->get('foo', 'nope', false), 'assoc indices of multi-valued headers are ignored');
105
- }
106
-
107
- public function testContains()
108
- {
109
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('foo' => 'bar', 'fuzz' => 'bizz'));
110
- $this->assertTrue($bag->contains('foo', 'bar'), '->contains first value');
111
- $this->assertTrue($bag->contains('fuzz', 'bizz'), '->contains second value');
112
- $this->assertFalse($bag->contains('nope', 'nope'), '->contains unknown value');
113
- $this->assertFalse($bag->contains('foo', 'nope'), '->contains unknown value');
114
-
115
- // Multiple values
116
- $bag->set('foo', 'bor', false);
117
- $this->assertTrue($bag->contains('foo', 'bar'), '->contains first value');
118
- $this->assertTrue($bag->contains('foo', 'bor'), '->contains second value');
119
- $this->assertFalse($bag->contains('foo', 'nope'), '->contains unknown value');
120
- }
121
-
122
- public function testCacheControlDirectiveAccessors()
123
- {
124
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag();
125
- $bag->addCacheControlDirective('public');
126
-
127
- $this->assertTrue($bag->hasCacheControlDirective('public'));
128
- $this->assertTrue($bag->getCacheControlDirective('public'));
129
- $this->assertEquals('public', $bag->get('cache-control'));
130
-
131
- $bag->addCacheControlDirective('max-age', 10);
132
- $this->assertTrue($bag->hasCacheControlDirective('max-age'));
133
- $this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
134
- $this->assertEquals('max-age=10, public', $bag->get('cache-control'));
135
-
136
- $bag->removeCacheControlDirective('max-age');
137
- $this->assertFalse($bag->hasCacheControlDirective('max-age'));
138
- }
139
-
140
- public function testCacheControlDirectiveParsing()
141
- {
142
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('cache-control' => 'public, max-age=10'));
143
- $this->assertTrue($bag->hasCacheControlDirective('public'));
144
- $this->assertTrue($bag->getCacheControlDirective('public'));
145
-
146
- $this->assertTrue($bag->hasCacheControlDirective('max-age'));
147
- $this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
148
-
149
- $bag->addCacheControlDirective('s-maxage', 100);
150
- $this->assertEquals('max-age=10, public, s-maxage=100', $bag->get('cache-control'));
151
- }
152
-
153
- public function testCacheControlDirectiveParsingQuotedZero()
154
- {
155
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('cache-control' => 'max-age="0"'));
156
- $this->assertTrue($bag->hasCacheControlDirective('max-age'));
157
- $this->assertEquals(0, $bag->getCacheControlDirective('max-age'));
158
- }
159
-
160
- public function testCacheControlDirectiveOverrideWithReplace()
161
- {
162
- $bag = new Ecocode_Profiler_Model_Http_HeaderBag(array('cache-control' => 'private, max-age=100'));
163
- $bag->replace(array('cache-control' => 'public, max-age=10'));
164
- $this->assertTrue($bag->hasCacheControlDirective('public'));
165
- $this->assertTrue($bag->getCacheControlDirective('public'));
166
-
167
- $this->assertTrue($bag->hasCacheControlDirective('max-age'));
168
- $this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
169
- }
170
-
171
- public function testGetIterator()
172
- {
173
- $headers = array('foo' => 'bar', 'hello' => 'world', 'third' => 'charm');
174
- $headerBag = new Ecocode_Profiler_Model_Http_HeaderBag($headers);
175
-
176
- $i = 0;
177
- foreach ($headerBag as $key => $val) {
178
- ++$i;
179
- $this->assertEquals(array($headers[$key]), $val);
180
- }
181
-
182
- $this->assertEquals(count($headers), $i);
183
- }
184
-
185
- public function testCount()
186
- {
187
- $headers = array('foo' => 'bar', 'HELLO' => 'WORLD');
188
- $headerBag = new Ecocode_Profiler_Model_Http_HeaderBag($headers);
189
-
190
- $this->assertEquals(count($headers), count($headerBag));
191
- }
192
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Http/ParameterBagTest.php DELETED
@@ -1,181 +0,0 @@
1
- <?php
2
-
3
-
4
- class ParameterBagTest extends \PHPUnit_Framework_TestCase
5
- {
6
- public function testConstructor()
7
- {
8
- $this->testAll();
9
- }
10
-
11
- public function testAll()
12
- {
13
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('foo' => 'bar'));
14
- $this->assertEquals(array('foo' => 'bar'), $bag->all(), '->all() gets all the input');
15
- }
16
-
17
- public function testKeys()
18
- {
19
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('foo' => 'bar'));
20
- $this->assertEquals(array('foo'), $bag->keys());
21
- }
22
-
23
- public function testAdd()
24
- {
25
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('foo' => 'bar'));
26
- $bag->add(array('bar' => 'bas'));
27
- $this->assertEquals(array('foo' => 'bar', 'bar' => 'bas'), $bag->all());
28
- }
29
-
30
- public function testRemove()
31
- {
32
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('foo' => 'bar'));
33
- $bag->add(array('bar' => 'bas'));
34
- $this->assertEquals(array('foo' => 'bar', 'bar' => 'bas'), $bag->all());
35
- $bag->remove('bar');
36
- $this->assertEquals(array('foo' => 'bar'), $bag->all());
37
- }
38
-
39
- public function testReplace()
40
- {
41
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('foo' => 'bar'));
42
-
43
- $bag->replace(array('FOO' => 'BAR'));
44
- $this->assertEquals(array('FOO' => 'BAR'), $bag->all(), '->replace() replaces the input with the argument');
45
- $this->assertFalse($bag->has('foo'), '->replace() overrides previously set the input');
46
- }
47
-
48
- public function testGet()
49
- {
50
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('foo' => 'bar', 'null' => null));
51
-
52
- $this->assertEquals('bar', $bag->get('foo'), '->get() gets the value of a parameter');
53
- $this->assertEquals('default', $bag->get('unknown', 'default'), '->get() returns second argument as default if a parameter is not defined');
54
- $this->assertNull($bag->get('null', 'default'), '->get() returns null if null is set');
55
- }
56
-
57
- public function testGetDoesNotUseDeepByDefault()
58
- {
59
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('foo' => array('bar' => 'moo')));
60
-
61
- $this->assertNull($bag->get('foo[bar]'));
62
- }
63
-
64
- public function testSet()
65
- {
66
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array());
67
-
68
- $bag->set('foo', 'bar');
69
- $this->assertEquals('bar', $bag->get('foo'), '->set() sets the value of parameter');
70
-
71
- $bag->set('foo', 'baz');
72
- $this->assertEquals('baz', $bag->get('foo'), '->set() overrides previously set parameter');
73
- }
74
-
75
- public function testHas()
76
- {
77
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('foo' => 'bar'));
78
-
79
- $this->assertTrue($bag->has('foo'), '->has() returns true if a parameter is defined');
80
- $this->assertFalse($bag->has('unknown'), '->has() return false if a parameter is not defined');
81
- }
82
-
83
- public function testGetAlpha()
84
- {
85
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('word' => 'foo_BAR_012'));
86
-
87
- $this->assertEquals('fooBAR', $bag->getAlpha('word'), '->getAlpha() gets only alphabetic characters');
88
- $this->assertEquals('', $bag->getAlpha('unknown'), '->getAlpha() returns empty string if a parameter is not defined');
89
- }
90
-
91
- public function testGetAlnum()
92
- {
93
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('word' => 'foo_BAR_012'));
94
-
95
- $this->assertEquals('fooBAR012', $bag->getAlnum('word'), '->getAlnum() gets only alphanumeric characters');
96
- $this->assertEquals('', $bag->getAlnum('unknown'), '->getAlnum() returns empty string if a parameter is not defined');
97
- }
98
-
99
- public function testGetDigits()
100
- {
101
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('word' => 'foo_BAR_012'));
102
-
103
- $this->assertEquals('012', $bag->getDigits('word'), '->getDigits() gets only digits as string');
104
- $this->assertEquals('', $bag->getDigits('unknown'), '->getDigits() returns empty string if a parameter is not defined');
105
- }
106
-
107
- public function testGetInt()
108
- {
109
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array('digits' => '0123'));
110
-
111
- $this->assertEquals(123, $bag->getInt('digits'), '->getInt() gets a value of parameter as integer');
112
- $this->assertEquals(0, $bag->getInt('unknown'), '->getInt() returns zero if a parameter is not defined');
113
- }
114
-
115
- public function testFilter()
116
- {
117
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag(array(
118
- 'digits' => '0123ab',
119
- 'email' => 'example@example.com',
120
- 'url' => 'http://example.com/foo',
121
- 'dec' => '256',
122
- 'hex' => '0x100',
123
- 'array' => array('bang'),
124
- ));
125
-
126
- $this->assertEmpty($bag->filter('nokey'), '->filter() should return empty by default if no key is found');
127
-
128
- $this->assertEquals('0123', $bag->filter('digits', '', FILTER_SANITIZE_NUMBER_INT), '->filter() gets a value of parameter as integer filtering out invalid characters');
129
-
130
- $this->assertEquals('example@example.com', $bag->filter('email', '', FILTER_VALIDATE_EMAIL), '->filter() gets a value of parameter as email');
131
-
132
- $this->assertEquals('http://example.com/foo', $bag->filter('url', '', FILTER_VALIDATE_URL, array('flags' => FILTER_FLAG_PATH_REQUIRED)), '->filter() gets a value of parameter as URL with a path');
133
-
134
- // This test is repeated for code-coverage
135
- $this->assertEquals('http://example.com/foo', $bag->filter('url', '', FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED), '->filter() gets a value of parameter as URL with a path');
136
-
137
- $this->assertFalse($bag->filter('dec', '', FILTER_VALIDATE_INT, array(
138
- 'flags' => FILTER_FLAG_ALLOW_HEX,
139
- 'options' => array('min_range' => 1, 'max_range' => 0xff),
140
- )), '->filter() gets a value of parameter as integer between boundaries');
141
-
142
- $this->assertFalse($bag->filter('hex', '', FILTER_VALIDATE_INT, array(
143
- 'flags' => FILTER_FLAG_ALLOW_HEX,
144
- 'options' => array('min_range' => 1, 'max_range' => 0xff),
145
- )), '->filter() gets a value of parameter as integer between boundaries');
146
-
147
- $this->assertEquals(array('bang'), $bag->filter('array', ''), '->filter() gets a value of parameter as an array');
148
- }
149
-
150
- public function testGetIterator()
151
- {
152
- $parameters = array('foo' => 'bar', 'hello' => 'world');
153
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag($parameters);
154
-
155
- $i = 0;
156
- foreach ($bag as $key => $val) {
157
- ++$i;
158
- $this->assertEquals($parameters[$key], $val);
159
- }
160
-
161
- $this->assertEquals(count($parameters), $i);
162
- }
163
-
164
- public function testCount()
165
- {
166
- $parameters = array('foo' => 'bar', 'hello' => 'world');
167
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag($parameters);
168
-
169
- $this->assertEquals(count($parameters), count($bag));
170
- }
171
-
172
- public function testGetBoolean()
173
- {
174
- $parameters = array('string_true' => 'true', 'string_false' => 'false');
175
- $bag = new Ecocode_Profiler_Model_Http_ParameterBag($parameters);
176
-
177
- $this->assertTrue($bag->getBoolean('string_true'), '->getBoolean() gets the string true as boolean true');
178
- $this->assertFalse($bag->getBoolean('string_false'), '->getBoolean() gets the string false as boolean false');
179
- $this->assertFalse($bag->getBoolean('unknown'), '->getBoolean() returns false if a parameter is not defined');
180
- }
181
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Http/ResponseHeaderBagTest.php DELETED
@@ -1,160 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * This file is part of the Symfony package.
5
- *
6
- * (c) Fabien Potencier <fabien@symfony.com>
7
- *
8
- * For the full copyright and license information, please view the LICENSE
9
- * file that was distributed with this source code.
10
- */
11
-
12
-
13
- /**
14
- * @group time-sensitive
15
- */
16
- class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
17
- {
18
- /**
19
- * @dataProvider provideAllPreserveCase
20
- */
21
- public function testAllPreserveCase($headers, $expected)
22
- {
23
- $bag = new Ecocode_Profiler_Model_Http_ResponseHeaderBag($headers);
24
-
25
- $this->assertEquals($expected, $bag->allPreserveCase(), '->allPreserveCase() gets all input keys in original case');
26
- }
27
-
28
- public function provideAllPreserveCase()
29
- {
30
- return array(
31
- array(
32
- array('fOo' => 'BAR'),
33
- array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache')),
34
- ),
35
- array(
36
- array('ETag' => 'xyzzy'),
37
- array('ETag' => array('xyzzy'), 'Cache-Control' => array('private, must-revalidate')),
38
- ),
39
- array(
40
- array('Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ=='),
41
- array('Content-MD5' => array('Q2hlY2sgSW50ZWdyaXR5IQ=='), 'Cache-Control' => array('no-cache')),
42
- ),
43
- array(
44
- array('P3P' => 'CP="CAO PSA OUR"'),
45
- array('P3P' => array('CP="CAO PSA OUR"'), 'Cache-Control' => array('no-cache')),
46
- ),
47
- array(
48
- array('WWW-Authenticate' => 'Basic realm="WallyWorld"'),
49
- array('WWW-Authenticate' => array('Basic realm="WallyWorld"'), 'Cache-Control' => array('no-cache')),
50
- ),
51
- array(
52
- array('X-UA-Compatible' => 'IE=edge,chrome=1'),
53
- array('X-UA-Compatible' => array('IE=edge,chrome=1'), 'Cache-Control' => array('no-cache')),
54
- ),
55
- array(
56
- array('X-XSS-Protection' => '1; mode=block'),
57
- array('X-XSS-Protection' => array('1; mode=block'), 'Cache-Control' => array('no-cache')),
58
- ),
59
- );
60
- }
61
-
62
- public function testReplace()
63
- {
64
- $bag = new Ecocode_Profiler_Model_Http_ResponseHeaderBag(array());
65
- $this->assertEquals('no-cache', $bag->get('Cache-Control'));
66
-
67
- $bag->replace(array('Cache-Control' => 'public'));
68
- $this->assertEquals('public', $bag->get('Cache-Control'));
69
- }
70
-
71
- public function testReplaceWithRemove()
72
- {
73
- $bag = new Ecocode_Profiler_Model_Http_ResponseHeaderBag(array());
74
- $this->assertEquals('no-cache', $bag->get('Cache-Control'));
75
-
76
- $bag->remove('Cache-Control');
77
- $bag->replace(array());
78
- $this->assertEquals('no-cache', $bag->get('Cache-Control'));
79
- }
80
-
81
-
82
- /**
83
- * @expectedException \InvalidArgumentException
84
- */
85
- public function testGetCookiesWithInvalidArgument()
86
- {
87
- $bag = new Ecocode_Profiler_Model_Http_ResponseHeaderBag();
88
-
89
- $cookies = $bag->getCookies('invalid_argument');
90
- }
91
-
92
- /**
93
- * @expectedException \InvalidArgumentException
94
- */
95
- public function testMakeDispositionInvalidDisposition()
96
- {
97
- $headers = new Ecocode_Profiler_Model_Http_ResponseHeaderBag();
98
-
99
- $headers->makeDisposition('invalid', 'foo.html');
100
- }
101
-
102
- /**
103
- * @dataProvider provideMakeDisposition
104
- */
105
- public function testMakeDisposition($disposition, $filename, $filenameFallback, $expected)
106
- {
107
- $headers = new Ecocode_Profiler_Model_Http_ResponseHeaderBag();
108
-
109
- $this->assertEquals($expected, $headers->makeDisposition($disposition, $filename, $filenameFallback));
110
- }
111
-
112
- public function testToStringDoesntMessUpHeaders()
113
- {
114
- $headers = new Ecocode_Profiler_Model_Http_ResponseHeaderBag();
115
-
116
- $headers->set('Location', 'http://www.symfony.com');
117
- $headers->set('Content-type', 'text/html');
118
-
119
- (string) $headers;
120
-
121
- $allHeaders = $headers->allPreserveCase();
122
- $this->assertEquals(array('http://www.symfony.com'), $allHeaders['Location']);
123
- $this->assertEquals(array('text/html'), $allHeaders['Content-type']);
124
- }
125
-
126
- public function provideMakeDisposition()
127
- {
128
- return array(
129
- array('attachment', 'foo.html', 'foo.html', 'attachment; filename="foo.html"'),
130
- array('attachment', 'foo.html', '', 'attachment; filename="foo.html"'),
131
- array('attachment', 'foo bar.html', '', 'attachment; filename="foo bar.html"'),
132
- array('attachment', 'foo "bar".html', '', 'attachment; filename="foo \\"bar\\".html"'),
133
- array('attachment', 'foo%20bar.html', 'foo bar.html', 'attachment; filename="foo bar.html"; filename*=utf-8\'\'foo%2520bar.html'),
134
- array('attachment', 'föö.html', 'foo.html', 'attachment; filename="foo.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
135
- );
136
- }
137
-
138
- /**
139
- * @dataProvider provideMakeDispositionFail
140
- * @expectedException \InvalidArgumentException
141
- */
142
- public function testMakeDispositionFail($disposition, $filename)
143
- {
144
- $headers = new Ecocode_Profiler_Model_Http_ResponseHeaderBag();
145
-
146
- $headers->makeDisposition($disposition, $filename);
147
- }
148
-
149
- public function provideMakeDispositionFail()
150
- {
151
- return array(
152
- array('attachment', 'foo%20bar.html'),
153
- array('attachment', 'foo/bar.html'),
154
- array('attachment', '/foo.html'),
155
- array('attachment', 'foo\bar.html'),
156
- array('attachment', '\foo.html'),
157
- array('attachment', 'föö.html'),
158
- );
159
- }
160
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/LoggerTest.php DELETED
@@ -1,87 +0,0 @@
1
- <?php
2
-
3
- use Monolog\Handler\TestHandler;
4
-
5
- class Ecocode_Profiler_Tests_Dev_Model_LoggerTest
6
- extends TestHelper
7
- {
8
- protected function setUp()
9
- {
10
- if (!class_exists('Monolog\Handler\TestHandler')) {
11
- $this->markTestSkipped(
12
- 'Monolog not installed skipping.'
13
- );
14
- }
15
- }
16
-
17
- public function testMageLog()
18
- {
19
- $handler = new Ecocode_Profiler_Model_Logger_DebugHandler();
20
- $logger = new Ecocode_Profiler_Model_Logger(__METHOD__, [$handler]);
21
-
22
- $this->assertTrue($logger->mageLog(Zend_Log::ERR, 'error message'));
23
- $logs = $logger->getLogs();
24
-
25
- $this->assertCount(1, $logs);
26
- $log = reset($logs);
27
- $this->assertEquals(Ecocode_Profiler_Model_Logger::ERROR, $log['priority']);
28
- }
29
-
30
- public function testGetLogsWithDebugHandler()
31
- {
32
- $handler = new Ecocode_Profiler_Model_Logger_DebugHandler();
33
- $logger = new Ecocode_Profiler_Model_Logger(__METHOD__, [$handler]);
34
-
35
- $this->assertTrue($logger->error('error message'));
36
- $this->assertSame(1, count($logger->getLogs()));
37
- }
38
-
39
- public function testGetLogsWithoutDebugHandler()
40
- {
41
- $handler = new TestHandler();
42
- $logger = new Ecocode_Profiler_Model_Logger(__METHOD__, [$handler]);
43
-
44
- $this->assertTrue($logger->error('error message'));
45
- $this->assertSame([], $logger->getLogs());
46
- }
47
-
48
- public function testCountErrorsWithDebugHandler()
49
- {
50
- $handler = new Ecocode_Profiler_Model_Logger_DebugHandler();
51
- $logger = new Ecocode_Profiler_Model_Logger(__METHOD__, [$handler]);
52
-
53
- $this->assertTrue($logger->debug('test message'));
54
- $this->assertTrue($logger->info('test message'));
55
- $this->assertTrue($logger->notice('test message'));
56
- $this->assertTrue($logger->warning('test message'));
57
-
58
- $this->assertTrue($logger->error('test message'));
59
- $this->assertTrue($logger->critical('test message'));
60
- $this->assertTrue($logger->alert('test message'));
61
- $this->assertTrue($logger->emergency('test message'));
62
-
63
- $this->assertSame(4, $logger->countErrors());
64
- }
65
-
66
- public function testGetLogs()
67
- {
68
- $logger = new Ecocode_Profiler_Model_Logger('test');
69
- $logger->pushHandler(new Ecocode_Profiler_Model_Logger_DebugHandler());
70
-
71
- $logger->addInfo('test');
72
- $this->assertCount(1, $logger->getLogs());
73
- list($record) = $logger->getLogs();
74
-
75
- $this->assertEquals('test', $record['message']);
76
- $this->assertEquals(Ecocode_Profiler_Model_Logger::INFO, $record['priority']);
77
- }
78
-
79
- public function testCountErrorsWithoutDebugHandler()
80
- {
81
- $handler = new TestHandler();
82
- $logger = new Ecocode_Profiler_Model_Logger(__METHOD__, [$handler]);
83
-
84
- $this->assertTrue($logger->error('error message'));
85
- $this->assertSame(0, $logger->countErrors());
86
- }
87
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Observer/ContextTest.php DELETED
@@ -1,66 +0,0 @@
1
- <?php
2
-
3
-
4
- class Ecocode_Profiler_Tests_Dev_Model_Observer_ContextTest
5
- extends TestHelper
6
- {
7
- protected $contextHelper;
8
-
9
- protected function setUp()
10
- {
11
- parent::setUp();
12
-
13
- /** @var Ecocode_Profiler_Helper_Context $contextHelper */
14
- $this->contextHelper = $this->getMockBuilder('Ecocode_Profiler_Helper_Context')
15
- ->getMock();
16
- }
17
-
18
-
19
- public function testOpenBlockContext()
20
- {
21
- /** @var Ecocode_Profiler_Model_Observer_Context $contextHelper */
22
- $observer = $this->getMockBuilder('Ecocode_Profiler_Model_Observer_Context')
23
- ->setMethods(['getHelper'])
24
- ->getMock();
25
-
26
- $observer->method('getHelper')->willReturn($this->contextHelper);
27
-
28
- $block = new Mage_Core_Block_Template();
29
- $block->setTemplate('test.phtml');
30
- $eventObserver = $this->getObserver(['block' => $block]);
31
-
32
- $this->contextHelper->expects($this->once())->method('open');
33
- $observer->openBlockContext($eventObserver);
34
-
35
- /** @var Ecocode_Profiler_Model_ContextInterface $context */
36
- $context = $block->getData('__context');
37
- $this->assertInstanceOf('Ecocode_Profiler_Model_ContextInterface', $context);
38
-
39
- return $block;
40
- }
41
-
42
- /**
43
- * @depends testOpenBlockContext
44
- */
45
- public function testCloseBlockContext(Mage_Core_Block_Template $block )
46
- {
47
- /** @var Ecocode_Profiler_Model_Observer_Context $contextHelper */
48
- $observer = $this->getMockBuilder('Ecocode_Profiler_Model_Observer_Context')
49
- ->setMethods(['getHelper'])
50
- ->getMock();
51
-
52
- $observer->method('getHelper')->willReturn($this->contextHelper);
53
-
54
- $eventObserver = $this->getObserver(['block' => $block]);
55
-
56
- $this->contextHelper->expects($this->once())->method('close');
57
- $observer->closeBlockContext($eventObserver);
58
-
59
- /** @var Ecocode_Profiler_Model_ContextInterface $context */
60
- $contextData = $block->getData('__context')->getData();
61
- $this->assertEquals('test.phtml', $contextData['template']);
62
-
63
-
64
- return $block;
65
- }
66
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/ObserverTest.php DELETED
@@ -1,163 +0,0 @@
1
- <?php
2
-
3
-
4
- class Ecocode_Profiler_Tests_Dev_Model_ObserverTest
5
- extends TestHelper
6
- {
7
- protected function setUp()
8
- {
9
- parent::setUp();
10
-
11
- /** @var Ecocode_Profiler_Helper_Context $contextHelper */
12
- $this->contextHelper = $this->getMockBuilder('Ecocode_Profiler_Helper_Context')
13
- ->getMock();
14
- }
15
-
16
-
17
- public function testControllerFrontSendResponseBefore()
18
- {
19
- /** @var Ecocode_Profiler_Model_Profiler $profiler */
20
- $profiler = $this->getMockBuilder('Ecocode_Profiler_Model_Profiler')
21
- ->setMethods(['saveProfile', 'collect'])
22
- ->getMock();
23
-
24
- $profiler->method('collect')
25
- ->willReturn(new Ecocode_Profiler_Model_Profile('xxx'));
26
-
27
-
28
- $profiler->disable();
29
- $this->checkIfToolbarIsInjected($profiler);
30
- $profiler->enable();
31
- $observer = $this->checkIfToolbarIsInjected($profiler);
32
-
33
- return $observer;
34
- }
35
-
36
- public function testLinkTokenHeader()
37
- {
38
- $profiler = $this->getMockBuilder('Ecocode_Profiler_Model_Profiler')
39
- ->setMethods(['collect'])
40
- ->getMock();
41
-
42
- $frontController = $this->getMockBuilder('Mage_Core_Controller_Varien_Front')
43
- ->setMethods(['getResponse'])
44
- ->getMock();
45
-
46
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
47
- $response->setHeader('X-Debug-Token', 'XXX');
48
-
49
- $frontController->method('getResponse')->willReturn($response);
50
-
51
- $eventObserver = $this->getObserver(['front' => $frontController]);
52
-
53
- $observer = $this->getMockBuilder('Ecocode_Profiler_Model_Observer')
54
- ->setMethods(['getProfiler', 'injectToolbar'])
55
- ->getMock();
56
-
57
-
58
- $observer->method('getProfiler')->willReturn($profiler);
59
-
60
- $profiler->enable();
61
- /** @var Ecocode_Profiler_Model_Observer $observer */
62
- $observer->controllerFrontSendResponseBefore($eventObserver);
63
-
64
- $headers = $response->getHeaders();
65
- $tokenLinkHeader = false;
66
- foreach ($headers as $header) {
67
- if ($header['name'] === 'X-Debug-Token-Link') {
68
- $tokenLinkHeader = $header;
69
- break;
70
- }
71
- }
72
- $this->assertNotFalse($tokenLinkHeader);
73
- }
74
-
75
- public function checkIfToolbarIsInjected(Ecocode_Profiler_Model_Profiler $profiler)
76
- {
77
- $frontController = $this->getMockBuilder('Mage_Core_Controller_Varien_Front')
78
- ->setMethods(['getResponse'])
79
- ->getMock();
80
-
81
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
82
-
83
- $frontController->method('getResponse')->willReturn($response);
84
-
85
- $eventObserver = $this->getObserver(['front' => $frontController]);
86
-
87
- $observer = $this->getMockBuilder('Ecocode_Profiler_Model_Observer')
88
- ->setMethods(['getProfiler', 'injectToolbar'])
89
- ->getMock();
90
-
91
-
92
- $observer->method('getProfiler')->willReturn($profiler);
93
-
94
- if ($profiler->isEnabled()) {
95
- $observer->expects($this->once())
96
- ->method('injectToolbar');
97
- } else {
98
- $observer->expects($this->never())
99
- ->method('injectToolbar');
100
- }
101
- /** @var Ecocode_Profiler_Model_Observer $observer */
102
- $observer->controllerFrontSendResponseBefore($eventObserver);
103
-
104
- return [$profiler, $observer];
105
- }
106
-
107
-
108
- /**
109
- */
110
- public function testOnTerminate()
111
- {
112
- $observer = $this->getMockBuilder('Ecocode_Profiler_Model_Observer')
113
- ->setMethods(['getProfiler'])
114
- ->getMock();
115
-
116
- $profilesProperty = new ReflectionProperty('Ecocode_Profiler_Model_Observer', 'profiles');
117
- $profilesProperty->setAccessible(true);
118
-
119
- $profile = new Ecocode_Profiler_Model_Profile('token');
120
-
121
- $request = new Mage_Core_Controller_Request_Http();
122
- $storage = $profilesProperty->getValue($observer);
123
- $storage[$request] = $profile;
124
-
125
-
126
- $profiler = $this->getMockBuilder('Ecocode_Profiler_Model_Profiler')
127
- ->setMethods(['saveProfile'])
128
- ->getMock();
129
-
130
- $observer->method('getProfiler')->willReturn($profiler);
131
-
132
- $profiler->expects($this->once())
133
- ->method('saveProfile');
134
-
135
- $observer->onTerminate($this->getObserver([]));
136
- }
137
-
138
-
139
- public function testInjectToolbar()
140
- {
141
- $layout = new Mage_Core_Model_Layout();
142
- $observer = $this->getMockBuilder('Ecocode_Profiler_Model_Observer')
143
- ->setMethods(['getLayout'])
144
- ->getMock();
145
-
146
- $observer->method('getLayout')->willReturn($layout);
147
-
148
- $injectToolbarMethod = new ReflectionMethod('Ecocode_Profiler_Model_Observer', 'injectToolbar');
149
- $injectToolbarMethod->setAccessible(true);
150
-
151
- $request = new Mage_Core_Controller_Request_Http();
152
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
153
- $response->setBody('<html><body>Some Content</body></html>');
154
-
155
- $injectToolbarMethod->invoke($observer, $response, $request);
156
-
157
- $this->assertContains('Some Content', $response->getBody());
158
- $this->assertContains('<!-- START of ecocode Web Debug Toolbar -->', $response->getBody());
159
-
160
- $this->assertNotFalse($layout->getBlock('profiler_toolbar'));
161
- $this->assertNotFalse($layout->getBlock('profiler_base_js'));
162
- }
163
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageCoreModelResourceDbAbstractTest.php DELETED
@@ -1,118 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Overwrite_MageCoreModelResourceDbAbstract
4
- extends TestHelper
5
- {
6
- public function testLoad()
7
- {
8
- $testData = ['a' => 'b'];
9
- $readAdapter = $this->getMockBuilder('Magento_Db_Adapter_Pdo_Mysql')
10
- ->disableOriginalConstructor()
11
- ->setMethods(['fetchRow'])
12
- ->getMock();
13
-
14
- $readAdapter->method('fetchRow')->willReturn($testData);
15
-
16
- $resourceLog = $this->getMockBuilder('Mage_Log_Model_Resource_Log')
17
- ->setMethods(['dispatch', '_getReadAdapter', '_getLoadSelect', 'unserializeFields', '_afterLoad'])
18
- ->getMock();
19
-
20
- $resourceLog->method('_getReadAdapter')->willReturn($readAdapter);
21
-
22
- $visitor = new Mage_Log_Model_Visitor();
23
-
24
-
25
- $resourceLog->expects($this->once())
26
- ->method('dispatch')
27
- ->with(
28
- $this->equalTo('model_resource_db_load'),
29
- $this->callback(function ($subject) use ($visitor) {
30
- return $subject['object'] === $visitor && isset($subject['time']);
31
- })
32
- );
33
-
34
-
35
- $resourceLog->load($visitor, 1);
36
- }
37
-
38
- public function testSave()
39
- {
40
- $writeAdapter = $this->getMockBuilder('Magento_Db_Adapter_Pdo_Mysql')
41
- ->disableOriginalConstructor()
42
- ->setMethods(['insert', 'lastInsertId'])
43
- ->getMock();
44
-
45
-
46
- $resourceLog = $this->getMockBuilder('Mage_Log_Model_Resource_Log')
47
- ->setMethods([
48
- 'dispatch', '_serializeFields', '_getWriteAdapter',
49
- '_beforeSave', '_checkUnique', '_prepareDataForSave',
50
- 'getIdFieldName', 'unserializeFields', 'afterSave'])
51
- ->getMock();
52
-
53
- $resourceLog->method('_getWriteAdapter')->willReturn($writeAdapter);
54
- $resourceLog->method('getIdFieldName')->willReturn('id');
55
- $resourceLog->method('_prepareDataForSave')->willReturn([]);
56
-
57
-
58
- $visitor = new Mage_Log_Model_Visitor();
59
- $resourceLog->expects($this->once())
60
- ->method('dispatch')
61
- ->with(
62
- $this->equalTo('model_resource_db_save'),
63
- $this->callback(function ($subject) use ($visitor) {
64
- return $subject['object'] === $visitor && isset($subject['time']);
65
- })
66
- );
67
-
68
-
69
- $resourceLog->save($visitor, 1);
70
- }
71
-
72
- public function testSaveDeleted()
73
- {
74
- $resourceLog = $this->getMockBuilder('Mage_Log_Model_Resource_Log')
75
- ->setMethods(['dispatch', 'delete'])
76
- ->getMock();
77
-
78
- $visitor = new Mage_Log_Model_Visitor();
79
- $visitor->isDeleted(true);
80
- $resourceLog->expects($this->never())
81
- ->method('dispatch');
82
-
83
- $resourceLog->save($visitor, 1);
84
- }
85
-
86
- public function testDelete()
87
- {
88
- $writeAdapter = $this->getMockBuilder('Magento_Db_Adapter_Pdo_Mysql')
89
- ->disableOriginalConstructor()
90
- ->setMethods(['delete', 'quoteInto'])
91
- ->getMock();
92
-
93
-
94
- $resourceLog = $this->getMockBuilder('Mage_Log_Model_Resource_Log')
95
- ->setMethods([
96
- 'dispatch', '_beforeDelete',
97
- 'getMainTable', '_getWriteAdapter',
98
- '_afterDelete'])
99
- ->getMock();
100
-
101
- $resourceLog->method('_getWriteAdapter')->willReturn($writeAdapter);
102
-
103
-
104
- $visitor = new Mage_Log_Model_Visitor();
105
-
106
- $resourceLog->expects($this->once())
107
- ->method('dispatch')
108
- ->with(
109
- $this->equalTo('model_resource_db_delete'),
110
- $this->callback(function ($subject) use ($visitor) {
111
- return $subject['object'] === $visitor && isset($subject['time']);
112
- })
113
- );
114
-
115
-
116
- $resourceLog->delete($visitor, 1);
117
- }
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageCoreModelResourceTest.php DELETED
@@ -1,29 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Overwrite_MageCoreModelResourceTest
4
- extends TestHelper
5
- {
6
-
7
-
8
- public function testGetConnection()
9
- {
10
- $configProperty = new ReflectionProperty('Varien_Db_Adapter_Pdo_Mysql', '_config');
11
- $configProperty->setAccessible(true);
12
-
13
- $resource = new Mage_Core_Model_Resource();
14
-
15
-
16
- /** @var Varien_Db_Adapter_Pdo_Mysql $connection */
17
- $connection = $resource->getConnection('core_read');
18
-
19
- $this->assertEquals(
20
- 'Ecocode_Profiler_Db_Statement_Pdo_Mysql',
21
- $connection->getStatementClass()
22
- );
23
-
24
-
25
- $connectionConfig = $configProperty->getValue($connection);
26
- $this->assertEquals('core_read', $connectionConfig['connection_name']);
27
-
28
- }
29
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageCoreModelTranslateTest.php DELETED
@@ -1,66 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Overwrite_MageCoreModelTranslateTest
4
- extends TestHelper
5
- {
6
- public function testTranslatedString()
7
- {
8
- $translate = new Mage_Core_Model_Translate();
9
-
10
-
11
- $this->addTranslations($translate, [
12
- 'test' => 'test-core'
13
- ], 'Mage_Core');
14
-
15
- $this->addTranslations($translate, [
16
- 'test' => 'test-page',
17
- 'test %' => 'test-page %s',
18
- ], 'Mage_Page');
19
-
20
-
21
- $this->assertTranslation($translate, 'test-core', 'test', 'none');
22
- $this->assertTranslation($translate, 'test-core', 'test', 'Mage_Core');
23
- $this->assertTranslation($translate, 'test-page', 'test', 'Mage_Page');
24
- $this->assertTranslation($translate, 'test-untranslated', 'test-untranslated', 'Mage_Page');
25
- $this->assertTranslation($translate, 'test %s', 'test %s', 'Mage_Page');
26
- $this->assertTranslation($translate, 'test-page asd', 'test %', 'Mage_Page', ['asd']);
27
-
28
- $stats = [];
29
- foreach ($translate->getMessages() as $message) {
30
- if (!isset($stats[$message['state']])) {
31
- $stats[$message['state']] = 0;
32
- }
33
- $stats[$message['state']]++;
34
- }
35
-
36
- $this->assertEquals(3, $stats[Mage_Core_Model_Translate::STATE_TRANSLATED]);
37
- $this->assertEquals(1, $stats[Mage_Core_Model_Translate::STATE_FALLBACK]);
38
- $this->assertEquals(1, $stats[Mage_Core_Model_Translate::STATE_MISSING]);
39
- $this->assertEquals(1, $stats[Mage_Core_Model_Translate::STATE_INVALID]);
40
- }
41
-
42
- protected function assertTranslation(Mage_Core_Model_Translate $translate, $expect, $key, $module, array $params = [])
43
- {
44
- $this->assertEquals($expect, $this->__($translate, $key, $module, $params));
45
- }
46
-
47
- protected function __(Mage_Core_Model_Translate $translate, $key, $module, array $params = [])
48
- {
49
- $expr = new Mage_Core_Model_Translate_Expr($key, $module);
50
-
51
- $args = $params;
52
- array_unshift($args, $expr);
53
- return $translate->translate($args);
54
- }
55
-
56
-
57
- protected function addTranslations($translate, $data, $scope)
58
- {
59
- $addDataMethod = new ReflectionMethod('Mage_Core_Model_Translate', '_addData');
60
- $addDataMethod->setAccessible(true);
61
-
62
- $addDataMethod->invoke($translate, $data, $scope);
63
-
64
- return $translate;
65
- }
66
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageEavModelEntityAbstractTest.php DELETED
@@ -1,111 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_Model_Overwrite_MageEavModelEntityAbstractTest
4
- extends TestHelper
5
- {
6
- public function testLoad()
7
- {
8
- $testData = ['a' => 'b'];
9
- $readAdapter = $this->getMockBuilder('Magento_Db_Adapter_Pdo_Mysql')
10
- ->disableOriginalConstructor()
11
- ->setMethods(['fetchRow'])
12
- ->getMock();
13
-
14
- $readAdapter->method('fetchRow')->willReturn($testData);
15
-
16
- $entityAbstract = $this->getMockBuilder('Mage_Eav_Model_Entity_Abstract')
17
- ->setMethods(['dispatch', '_getReadAdapter', '_getLoadRowSelect', 'loadAllAttributes'])
18
- ->getMock();
19
-
20
- $entityAbstract->method('_getReadAdapter')->willReturn($readAdapter);
21
-
22
- $product = new Mage_Catalog_Model_Product();
23
-
24
-
25
- $entityAbstract->expects($this->once())
26
- ->method('dispatch')
27
- ->with(
28
- $this->equalTo('model_resource_db_load'),
29
- $this->callback(function($subject) use ($product) {
30
- return $subject['object'] === $product && isset($subject['time']);
31
- })
32
- );
33
-
34
-
35
- $entityAbstract->load($product, 1);
36
- }
37
-
38
- public function testSave()
39
- {
40
- $entityAbstract = $this->getMockBuilder('Mage_Eav_Model_Entity_Abstract')
41
- ->setMethods(['dispatch', 'loadAllAttributes', '_beforeSave', '_processSaveData', '_collectSaveData', '_afterSave'])
42
- ->getMock();
43
-
44
- $product = new Mage_Catalog_Model_Product();
45
- $product->setData('entity_type_id', 1);
46
-
47
- $entityAbstract->expects($this->once())
48
- ->method('dispatch')
49
- ->with(
50
- $this->equalTo('model_resource_db_save'),
51
- $this->callback(function($subject) use ($product) {
52
- return $subject['object'] === $product && isset($subject['time']);
53
- })
54
- );
55
-
56
-
57
- $entityAbstract->save($product, 1);
58
- }
59
-
60
- public function testSaveDeleted()
61
- {
62
- $entityAbstract = $this->getMockBuilder('Mage_Eav_Model_Entity_Abstract')
63
- ->setMethods(['dispatch', 'delete', 'loadAllAttributes', '_beforeSave', '_processSaveData', '_collectSaveData', '_afterSave'])
64
- ->getMock();
65
-
66
- $product = new Mage_Catalog_Model_Product();
67
- $product->setData('entity_type_id', 1);
68
- $product->isDeleted(true);
69
- $entityAbstract->expects($this->never())
70
- ->method('dispatch');
71
-
72
-
73
- $entityAbstract->save($product, 1);
74
- }
75
-
76
- public function testDelete()
77
- {
78
- $writeAdapter = $this->getMockBuilder('Magento_Db_Adapter_Pdo_Mysql')
79
- ->disableOriginalConstructor()
80
- ->setMethods(['delete'])
81
- ->getMock();
82
-
83
-
84
- $entityAbstract = $this->getMockBuilder('Mage_Eav_Model_Entity_Abstract')
85
- ->setMethods([
86
- 'dispatch', '_beforeDelete',
87
- 'getEntityIdField', '_getWriteAdapter',
88
- 'getEntityTable', 'loadAllAttributes', '_afterDelete'])
89
- ->getMock();
90
-
91
- $entityAbstract->method('_getWriteAdapter')->willReturn($writeAdapter);
92
- $entityAbstract->method('getEntityIdField')->willReturn('id');
93
-
94
-
95
- $product = new Mage_Catalog_Model_Product();
96
- $product->setData('entity_type_id', 1);
97
-
98
- $entityAbstract->expects($this->once())
99
- ->method('dispatch')
100
- ->with(
101
- $this->equalTo('model_resource_db_delete'),
102
- $this->callback(function($subject) use ($product) {
103
- return $subject['object'] === $product && isset($subject['time']);
104
- })
105
- );
106
-
107
-
108
-
109
- $entityAbstract->delete($product, 1);
110
- }
111
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Overwrite/MageTest.php DELETED
@@ -1,43 +0,0 @@
1
- <?php
2
-
3
-
4
- class Ecocode_Profiler_Tests_Dev_Model_Overwrite_MageTest
5
- extends TestHelper
6
- {
7
- public function testGetLogger()
8
- {
9
- if (!class_exists('Monolog\Handler\TestHandler')) {
10
- $this->markTestSkipped(
11
- 'Monolog not installed skipping.'
12
- );
13
- }
14
- $logger = Mage::getLogger();
15
-
16
- $this->assertInstanceOf('Ecocode_Profiler_Model_Logger', $logger);
17
- $this->assertEquals(Mage::getDefaultLogger(), $logger);
18
-
19
- $this->assertNotEquals(Mage::getDefaultLogger(), Mage::getLogger('new'));
20
- }
21
-
22
- public function testLog()
23
- {
24
- if (!class_exists('Monolog\Handler\TestHandler')) {
25
- $this->markTestSkipped(
26
- 'Monolog not installed skipping.'
27
- );
28
- }
29
- $logger = Mage::getLogger();
30
-
31
- $this->assertCount(0, $logger->getLogs());
32
-
33
- Mage::log('test');
34
- Mage::log('test', Zend_Log::ALERT, 'error.log');
35
-
36
- $logs = $logger->getLogs();
37
- $this->assertCount(2, $logs);
38
- $lastLog = end($logs);
39
-
40
- $this->assertEquals(Ecocode_Profiler_Model_Logger::ALERT, $lastLog['priority']);
41
- $this->assertEquals('error', $lastLog['channel']);
42
- }
43
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/Profiler/FileStorageTest.php DELETED
@@ -1,346 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * This file is part of the Symfony package.
5
- *
6
- * (c) Fabien Potencier <fabien@symfony.com>
7
- *
8
- * For the full copyright and license information, please view the LICENSE
9
- * file that was distributed with this source code.
10
- */
11
-
12
-
13
- class Ecocode_Profiler_Tests_Dev_Model_Profiler_FileStorageTest
14
- extends \TestHelper
15
- {
16
- private $tmpDir;
17
- private $storage;
18
-
19
- protected function setUp()
20
- {
21
- $this->tmpDir = sys_get_temp_dir() . '/sf2_profiler_file_storage';
22
- if (is_dir($this->tmpDir)) {
23
- self::cleanDir();
24
- }
25
- $this->storage = new Ecocode_Profiler_Model_Profiler_FileStorage(['dsn' => 'file:' . $this->tmpDir]);
26
- $this->storage->purge();
27
- }
28
-
29
- protected function tearDown()
30
- {
31
- self::cleanDir();
32
- }
33
-
34
- public function testStore()
35
- {
36
- for ($i = 0; $i < 10; ++$i) {
37
- $profile = new Ecocode_Profiler_Model_Profile('token_' . $i);
38
- $profile->setIp('127.0.0.1');
39
- $profile->setUrl('http://foo.bar');
40
- $profile->setMethod('GET');
41
- $this->storage->write($profile);
42
- }
43
- $this->assertCount(10, $this->storage->find('127.0.0.1', 'http://foo.bar', 20, 'GET'), '->write() stores data in the storage');
44
- }
45
-
46
- public function testChildren()
47
- {
48
- $parentProfile = new Ecocode_Profiler_Model_Profile('token_parent');
49
- $parentProfile->setIp('127.0.0.1');
50
- $parentProfile->setUrl('http://foo.bar/parent');
51
-
52
- $childProfile = new Ecocode_Profiler_Model_Profile('token_child');
53
- $childProfile->setIp('127.0.0.1');
54
- $childProfile->setUrl('http://foo.bar/child');
55
-
56
- $parentProfile->addChild($childProfile);
57
-
58
- $this->storage->write($parentProfile);
59
- $this->storage->write($childProfile);
60
-
61
- // Load them from storage
62
- $parentProfile = $this->storage->read('token_parent');
63
- $childProfile = $this->storage->read('token_child');
64
-
65
- // Check child has link to parent
66
- $this->assertNotNull($childProfile->getParent());
67
- $this->assertEquals($parentProfile->getToken(), $childProfile->getParentToken());
68
-
69
- // Check parent has child
70
- $children = $parentProfile->getChildren();
71
- $this->assertCount(1, $children);
72
- $this->assertEquals($childProfile->getToken(), $children[0]->getToken());
73
- }
74
-
75
- public function testStoreSpecialCharsInUrl()
76
- {
77
- // The storage accepts special characters in URLs (Even though URLs are not
78
- // supposed to contain them)
79
- $profile = new Ecocode_Profiler_Model_Profile('simple_quote');
80
- $profile->setUrl('http://foo.bar/\'');
81
- $this->storage->write($profile);
82
- $this->assertTrue(false !== $this->storage->read('simple_quote'), '->write() accepts single quotes in URL');
83
-
84
- $profile = new Ecocode_Profiler_Model_Profile('double_quote');
85
- $profile->setUrl('http://foo.bar/"');
86
- $this->storage->write($profile);
87
- $this->assertTrue(false !== $this->storage->read('double_quote'), '->write() accepts double quotes in URL');
88
-
89
- $profile = new Ecocode_Profiler_Model_Profile('backslash');
90
- $profile->setUrl('http://foo.bar/\\');
91
- $this->storage->write($profile);
92
- $this->assertTrue(false !== $this->storage->read('backslash'), '->write() accepts backslash in URL');
93
-
94
- $profile = new Ecocode_Profiler_Model_Profile('comma');
95
- $profile->setUrl('http://foo.bar/,');
96
- $this->storage->write($profile);
97
- $this->assertTrue(false !== $this->storage->read('comma'), '->write() accepts comma in URL');
98
- }
99
-
100
- public function testStoreDuplicateToken()
101
- {
102
- $profile = new Ecocode_Profiler_Model_Profile('token');
103
- $profile->setUrl('http://example.com/');
104
-
105
- $this->assertTrue($this->storage->write($profile), '->write() returns true when the token is unique');
106
-
107
- $profile->setUrl('http://example.net/');
108
-
109
- $this->assertTrue($this->storage->write($profile), '->write() returns true when the token is already present in the storage');
110
- $this->assertEquals('http://example.net/', $this->storage->read('token')->getUrl(), '->write() overwrites the current profile data');
111
-
112
- $this->assertCount(1, $this->storage->find('', '', 1000, ''), '->find() does not return the same profile twice');
113
- }
114
-
115
- public function testRetrieveByIp()
116
- {
117
- $profile = new Ecocode_Profiler_Model_Profile('token');
118
- $profile->setIp('127.0.0.1');
119
- $profile->setMethod('GET');
120
- $this->storage->write($profile);
121
-
122
- $this->assertCount(1, $this->storage->find('127.0.0.1', '', 10, 'GET'), '->find() retrieve a record by IP');
123
- $this->assertCount(0, $this->storage->find('127.0.%.1', '', 10, 'GET'), '->find() does not interpret a "%" as a wildcard in the IP');
124
- $this->assertCount(0, $this->storage->find('127.0._.1', '', 10, 'GET'), '->find() does not interpret a "_" as a wildcard in the IP');
125
- }
126
-
127
- public function testRetrieveByStatusCode()
128
- {
129
- $profile200 = new Ecocode_Profiler_Model_Profile('statuscode200');
130
- $profile200->setStatusCode(200);
131
- $this->storage->write($profile200);
132
-
133
- $profile404 = new Ecocode_Profiler_Model_Profile('statuscode404');
134
- $profile404->setStatusCode(404);
135
- $this->storage->write($profile404);
136
-
137
- $this->assertCount(1, $this->storage->find(null, null, 10, null, null, null, '200'), '->find() retrieve a record by Status code 200');
138
- $this->assertCount(1, $this->storage->find(null, null, 10, null, null, null, '404'), '->find() retrieve a record by Status code 404');
139
- }
140
-
141
- public function testRetrieveByUrl()
142
- {
143
- $profile = new Ecocode_Profiler_Model_Profile('simple_quote');
144
- $profile->setIp('127.0.0.1');
145
- $profile->setUrl('http://foo.bar/\'');
146
- $profile->setMethod('GET');
147
- $this->storage->write($profile);
148
-
149
- $profile = new Ecocode_Profiler_Model_Profile('double_quote');
150
- $profile->setIp('127.0.0.1');
151
- $profile->setUrl('http://foo.bar/"');
152
- $profile->setMethod('GET');
153
- $this->storage->write($profile);
154
-
155
- $profile = new Ecocode_Profiler_Model_Profile('backslash');
156
- $profile->setIp('127.0.0.1');
157
- $profile->setUrl('http://foo\\bar/');
158
- $profile->setMethod('GET');
159
- $this->storage->write($profile);
160
-
161
- $profile = new Ecocode_Profiler_Model_Profile('percent');
162
- $profile->setIp('127.0.0.1');
163
- $profile->setUrl('http://foo.bar/%');
164
- $profile->setMethod('GET');
165
- $this->storage->write($profile);
166
-
167
- $profile = new Ecocode_Profiler_Model_Profile('underscore');
168
- $profile->setIp('127.0.0.1');
169
- $profile->setUrl('http://foo.bar/_');
170
- $profile->setMethod('GET');
171
- $this->storage->write($profile);
172
-
173
- $profile = new Ecocode_Profiler_Model_Profile('semicolon');
174
- $profile->setIp('127.0.0.1');
175
- $profile->setUrl('http://foo.bar/;');
176
- $profile->setMethod('GET');
177
- $this->storage->write($profile);
178
-
179
- $this->assertCount(1, $this->storage->find('127.0.0.1', 'http://foo.bar/\'', 10, 'GET'), '->find() accepts single quotes in URLs');
180
- $this->assertCount(1, $this->storage->find('127.0.0.1', 'http://foo.bar/"', 10, 'GET'), '->find() accepts double quotes in URLs');
181
- $this->assertCount(1, $this->storage->find('127.0.0.1', 'http://foo\\bar/', 10, 'GET'), '->find() accepts backslash in URLs');
182
- $this->assertCount(1, $this->storage->find('127.0.0.1', 'http://foo.bar/;', 10, 'GET'), '->find() accepts semicolon in URLs');
183
- $this->assertCount(1, $this->storage->find('127.0.0.1', 'http://foo.bar/%', 10, 'GET'), '->find() does not interpret a "%" as a wildcard in the URL');
184
- $this->assertCount(1, $this->storage->find('127.0.0.1', 'http://foo.bar/_', 10, 'GET'), '->find() does not interpret a "_" as a wildcard in the URL');
185
- }
186
-
187
- public function testStoreTime()
188
- {
189
- $dt = new \DateTime('now');
190
- $start = $dt->getTimestamp();
191
-
192
- for ($i = 0; $i < 3; ++$i) {
193
- $dt->modify('+1 minute');
194
- $profile = new Ecocode_Profiler_Model_Profile('time_' . $i);
195
- $profile->setIp('127.0.0.1');
196
- $profile->setUrl('http://foo.bar');
197
- $profile->setTime($dt->getTimestamp());
198
- $profile->setMethod('GET');
199
- $this->storage->write($profile);
200
- }
201
-
202
- $records = $this->storage->find('', '', 3, 'GET', $start, time() + 3 * 60);
203
- $this->assertCount(3, $records, '->find() returns all previously added records');
204
- $this->assertEquals($records[0]['token'], 'time_2', '->find() returns records ordered by time in descendant order');
205
- $this->assertEquals($records[1]['token'], 'time_1', '->find() returns records ordered by time in descendant order');
206
- $this->assertEquals($records[2]['token'], 'time_0', '->find() returns records ordered by time in descendant order');
207
-
208
- $records = $this->storage->find('', '', 3, 'GET', $start, time() + 2 * 60);
209
- $this->assertCount(2, $records, '->find() should return only first two of the previously added records');
210
- }
211
-
212
- public function testRetrieveByEmptyUrlAndIp()
213
- {
214
- for ($i = 0; $i < 5; ++$i) {
215
- $profile = new Ecocode_Profiler_Model_Profile('token_' . $i);
216
- $profile->setMethod('GET');
217
- $this->storage->write($profile);
218
- }
219
- $this->assertCount(5, $this->storage->find('', '', 10, 'GET'), '->find() returns all previously added records');
220
- $this->storage->purge();
221
- }
222
-
223
- public function testRetrieveByMethodAndLimit()
224
- {
225
- foreach (['POST', 'GET'] as $method) {
226
- for ($i = 0; $i < 5; ++$i) {
227
- $profile = new Ecocode_Profiler_Model_Profile('token_' . $i . $method);
228
- $profile->setMethod($method);
229
- $this->storage->write($profile);
230
- }
231
- }
232
-
233
- $this->assertCount(5, $this->storage->find('', '', 5, 'POST'));
234
-
235
- $this->storage->purge();
236
- }
237
-
238
- public function testPurge()
239
- {
240
- $profile = new Ecocode_Profiler_Model_Profile('token1');
241
- $profile->setIp('127.0.0.1');
242
- $profile->setUrl('http://example.com/');
243
- $profile->setMethod('GET');
244
- $this->storage->write($profile);
245
-
246
- $this->assertTrue(false !== $this->storage->read('token1'));
247
- $this->assertCount(1, $this->storage->find('127.0.0.1', '', 10, 'GET'));
248
-
249
- $profile = new Ecocode_Profiler_Model_Profile('token2');
250
- $profile->setIp('127.0.0.1');
251
- $profile->setUrl('http://example.net/');
252
- $profile->setMethod('GET');
253
- $this->storage->write($profile);
254
-
255
- $this->assertTrue(false !== $this->storage->read('token2'));
256
- $this->assertCount(2, $this->storage->find('127.0.0.1', '', 10, 'GET'));
257
-
258
- $this->storage->purge();
259
-
260
- $this->assertEmpty($this->storage->read('token'), '->purge() removes all data stored by profiler');
261
- $this->assertCount(0, $this->storage->find('127.0.0.1', '', 10, 'GET'), '->purge() removes all items from index');
262
- }
263
-
264
- public function testDuplicates()
265
- {
266
- for ($i = 1; $i <= 5; ++$i) {
267
- $profile = new Ecocode_Profiler_Model_Profile('foo' . $i);
268
- $profile->setIp('127.0.0.1');
269
- $profile->setUrl('http://example.net/');
270
- $profile->setMethod('GET');
271
-
272
- ///three duplicates
273
- $this->storage->write($profile);
274
- $this->storage->write($profile);
275
- $this->storage->write($profile);
276
- }
277
- $this->assertCount(3, $this->storage->find('127.0.0.1', 'http://example.net/', 3, 'GET'), '->find() method returns incorrect number of entries');
278
- }
279
-
280
- public function testStatusCode()
281
- {
282
- $profile = new Ecocode_Profiler_Model_Profile('token1');
283
- $profile->setStatusCode(200);
284
- $this->storage->write($profile);
285
-
286
- $profile = new Ecocode_Profiler_Model_Profile('token2');
287
- $profile->setStatusCode(404);
288
- $this->storage->write($profile);
289
-
290
- $tokens = $this->storage->find('', '', 10, '');
291
- $this->assertCount(2, $tokens);
292
- $this->assertContains($tokens[0]['status_code'], [200, 404]);
293
- $this->assertContains($tokens[1]['status_code'], [200, 404]);
294
- }
295
-
296
- public function testMultiRowIndexFile()
297
- {
298
- $iteration = 3;
299
- for ($i = 0; $i < $iteration; ++$i) {
300
- $profile = new Ecocode_Profiler_Model_Profile('token' . $i);
301
- $profile->setIp('127.0.0.' . $i);
302
- $profile->setUrl('http://foo.bar/' . $i);
303
-
304
- $this->storage->write($profile);
305
- $this->storage->write($profile);
306
- $this->storage->write($profile);
307
- }
308
-
309
- $handle = fopen($this->tmpDir . '/index.csv', 'r');
310
- for ($i = 0; $i < $iteration; ++$i) {
311
- $row = fgetcsv($handle);
312
- $this->assertEquals('token' . $i, $row[0]);
313
- $this->assertEquals('127.0.0.' . $i, $row[1]);
314
- $this->assertEquals('http://foo.bar/' . $i, $row[3]);
315
- }
316
- $this->assertFalse(fgetcsv($handle));
317
- }
318
-
319
- public function testReadLineFromFile()
320
- {
321
- $r = new \ReflectionMethod($this->storage, 'readLineFromFile');
322
-
323
- $r->setAccessible(true);
324
-
325
- $h = tmpfile();
326
-
327
- fwrite($h, "line1\n\n\nline2\n");
328
- fseek($h, 0, SEEK_END);
329
-
330
- $this->assertEquals('line2', $r->invoke($this->storage, $h));
331
- $this->assertEquals('line1', $r->invoke($this->storage, $h));
332
- }
333
-
334
- protected function cleanDir()
335
- {
336
- $flags = \FilesystemIterator::SKIP_DOTS;
337
- $iterator = new \RecursiveDirectoryIterator($this->tmpDir, $flags);
338
- $iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
339
-
340
- foreach ($iterator as $file) {
341
- if (is_file($file)) {
342
- unlink($file);
343
- }
344
- }
345
- }
346
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/Model/ProfilerTest.php DELETED
@@ -1,58 +0,0 @@
1
- <?php
2
-
3
-
4
- class Ecocode_Profiler_Tests_Dev_Model_ProfilerTest extends TestHelper
5
- {
6
- private $tmp;
7
- /** @var Ecocode_Profiler_Model_Profiler_FileStorage */
8
- private $storage;
9
-
10
- public function testFindWorksWithDates()
11
- {
12
- $profiler = new Ecocode_Profiler_Model_Profiler($this->storage);
13
-
14
- $this->assertCount(0, $profiler->find(null, null, null, null, '7th April 2014', '9th April 2014'));
15
- }
16
-
17
- public function testFindWorksWithTimestamps()
18
- {
19
- $profiler = new Ecocode_Profiler_Model_Profiler($this->storage);
20
-
21
- $this->assertCount(0, $profiler->find(null, null, null, null, '1396828800', '1397001600'));
22
- }
23
-
24
- public function testFindWorksWithInvalidDates()
25
- {
26
- $profiler = new Ecocode_Profiler_Model_Profiler($this->storage);
27
-
28
- $this->assertCount(0, $profiler->find(null, null, null, null, 'some string', ''));
29
- }
30
-
31
- public function testFindWorksWithStatusCode()
32
- {
33
- $profiler = new Ecocode_Profiler_Model_Profiler($this->storage);
34
-
35
- $this->assertCount(0, $profiler->find(null, null, null, null, null, null, '204'));
36
- }
37
-
38
- protected function setUp()
39
- {
40
- $this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
41
- if (file_exists($this->tmp)) {
42
- @unlink($this->tmp);
43
- }
44
-
45
- $this->storage = new Ecocode_Profiler_Model_Profiler_FileStorage(['dsn' => 'file:' . $this->tmp]);
46
- $this->storage->purge();
47
- }
48
-
49
- protected function tearDown()
50
- {
51
- if (null !== $this->storage) {
52
- $this->storage->purge();
53
- $this->storage = null;
54
-
55
- @unlink($this->tmp);
56
- }
57
- }
58
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/bootstrap.php DELETED
@@ -1,54 +0,0 @@
1
- <?php
2
-
3
- if (isset($_SERVER['MAGENTO_DIRECTORY'])) {
4
- $_baseDir = $_SERVER['MAGENTO_DIRECTORY'];
5
- } else {
6
- $_baseDir = getcwd();
7
- }
8
-
9
- /**
10
- * Define MAGE_PATH
11
- * Path to Magento
12
- */
13
- define('MAGENTO_ROOT', $_baseDir);
14
-
15
- // Include Mage file by detecting app root
16
- require_once $_baseDir . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'MageDev.php';
17
-
18
- if (!Mage::isInstalled()) {
19
- throw new RuntimeException('Magento Unit Tests can run only on installed version');
20
- }
21
-
22
-
23
- /* Replace server variables for proper file naming */
24
- $_SERVER['SCRIPT_NAME'] = $_baseDir . DS . 'index.php';
25
- $_SERVER['SCRIPT_FILENAME'] = $_baseDir . DS . 'index.php';
26
-
27
- //fill the session to prevent session_start issues
28
- $_SESSION = ['x' => 'y'];
29
-
30
- //flag to check for unittets
31
- define('BASE_TESTS_PATH', realpath(dirname(__FILE__)));
32
- require_once BASE_TESTS_PATH . '/../TestHelper.php';
33
-
34
- $options = [
35
- 'cache' => ['id_prefix' => 'test-dev'],
36
- 'config_model' => 'Ecocode_Profiler_Model_Core_Config'
37
- ];
38
- Mage::app('', 'store', $options);
39
-
40
- // Removing Varien Autoload, to prevent errors with PHPUnit components
41
- spl_autoload_unregister([\Varien_Autoload::instance(), 'autoload']);
42
- spl_autoload_register(function ($className) {
43
- $filePath = strtr(
44
- ltrim($className, '\\'),
45
- [
46
- '\\' => '/',
47
- '_' => '/'
48
- ]
49
- );
50
- $file = $filePath . '.php';
51
- if (stream_resolve_include_path($file)) {
52
- include $filePath . '.php';
53
- }
54
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Dev/controllers/CacheControllerTest.php DELETED
@@ -1,168 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_Dev_CacheControllerTest extends TestHelper
4
- {
5
- protected function getMockedController($class, $request = null, $response = null, $app = null)
6
- {
7
- if (!$request instanceof Mage_Core_Controller_Request_Http) {
8
- $_request = new Mage_Core_Controller_Request_Http();
9
- if (is_array($request)) {
10
- $_request->setParams($request);
11
-
12
- }
13
- $request = $_request;
14
-
15
- }
16
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
17
- $appMock = $app ? $app : $this->getMockBuilder('Mage_Core_Model_App')->getMock();
18
-
19
- $controller = $this->getMockBuilder($class)
20
- ->setMethods(['getApp'])
21
- ->setConstructorArgs([$request, $response])
22
- ->getMock();
23
-
24
- $controller->method('getApp')
25
- ->willReturn($appMock);
26
-
27
-
28
- return $controller;
29
- }
30
-
31
- public function setUp()
32
- {
33
- parent::setUp();
34
-
35
- require_once Mage::getModuleDir('controllers', 'Ecocode_Profiler') . DS . 'CacheController.php';
36
- }
37
-
38
-
39
- public function testClearAction()
40
- {
41
- $appMock = $this->getMockBuilder('Mage_Core_Model_App')->getMock();
42
- $controller = $this->getMockedController(
43
- 'Ecocode_Profiler_CacheController',
44
- ['types' => join(',', ['test', 'block_html', 'config'])],
45
- null, $appMock
46
- );
47
-
48
- $cache = $this->getMockBuilder('Mage_Core_Model_Cache')->getMock();
49
- $appMock->method('getCacheInstance')
50
- ->willReturn($cache);
51
-
52
- $cache
53
- ->expects($this->exactly(3))
54
- ->method('cleanType');
55
-
56
-
57
- /** @var Ecocode_Profiler_CacheController $controller */
58
- $controller->clearAction();
59
- }
60
-
61
- public function testClearAllAction()
62
- {
63
- $appMock = $this->getMockBuilder('Mage_Core_Model_App')->getMock();
64
- $controller = $this->getMockedController(
65
- 'Ecocode_Profiler_CacheController',
66
- null, null, $appMock
67
- );
68
-
69
- $cache = $this->getMockBuilder('Mage_Core_Model_Cache')->getMock();
70
- $appMock->method('getCacheInstance')
71
- ->willReturn($cache);
72
-
73
- $cache
74
- ->expects($this->once())
75
- ->method('flush');
76
-
77
- /** @var Ecocode_Profiler_CacheController $controller */
78
- $controller->clearAllAction();
79
- }
80
-
81
- public function testEnableAction()
82
- {
83
- $request = new Mage_Core_Controller_Request_Http();
84
- $request->setParams(['types' => 'config,block_html']);
85
-
86
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
87
- $controller = $this->getMockBuilder('Ecocode_Profiler_CacheController')
88
- ->setMethods(['setCacheStatus'])
89
- ->setConstructorArgs([$request, $response])
90
- ->getMock();
91
-
92
-
93
- $controller
94
- ->expects($this->once())
95
- ->method('setCacheStatus')
96
- ->with(
97
- $this->equalTo(['config', 'block_html']),
98
- $this->equalTo(1)
99
- );
100
-
101
- /** @var Ecocode_Profiler_CacheController $controller */
102
- $controller->enableAction();
103
- }
104
-
105
- public function testDisableAction()
106
- {
107
- $request = new Mage_Core_Controller_Request_Http();
108
- $request->setParams(['types' => 'config,block_html']);
109
-
110
- $response = new Ecocode_Profiler_Tests_Dev_Fixtures_ResponseHttp();
111
- $controller = $this->getMockBuilder('Ecocode_Profiler_CacheController')
112
- ->setMethods(['setCacheStatus'])
113
- ->setConstructorArgs([$request, $response])
114
- ->getMock();
115
-
116
-
117
- $controller
118
- ->expects($this->once())
119
- ->method('setCacheStatus')
120
- ->with(
121
- $this->equalTo(['config', 'block_html']),
122
- $this->equalTo(0)
123
- );
124
-
125
- /** @var Ecocode_Profiler_CacheController $controller */
126
- $controller->disableAction();
127
- }
128
-
129
- public function testSetCacheStatus()
130
- {
131
- $types = [
132
- 'config' => new Varien_Object(['id' => 'config', 'status' => 0]),
133
- 'block_html' => new Varien_Object(['id' => 'block_html', 'status' => 0])
134
- ];
135
-
136
-
137
- $cacheMock = $this->getMockBuilder('Mage_Core_Model_Cache')
138
- ->getMock();
139
- $cacheMock->method('getTypes')->willReturn($types);
140
-
141
- $appMock = $this->getMockBuilder('Mage_Core_Model_App')
142
- ->setMethods(['saveUseCache', 'getCacheInstance', 'getCache'])
143
- ->getMock();
144
-
145
- $appMock->method('getCacheInstance')->willReturn($cacheMock);
146
- $appMock->method('getCache')->willReturn($cacheMock);
147
-
148
- $this->initApp($appMock);
149
- $controller = $this->getMockedController(
150
- 'Ecocode_Profiler_CacheController',
151
- null, null, $appMock
152
- );
153
-
154
- $status = 1;
155
-
156
- $setCacheStatusMethod = new ReflectionMethod('Ecocode_Profiler_CacheController', 'setCacheStatus');
157
- $setCacheStatusMethod->setAccessible(true);
158
-
159
- $types = array_fill_keys(array_keys($types), 0);
160
- $types['block_html'] = 1;
161
-
162
- $appMock->expects($this->once())
163
- ->method('saveUseCache')
164
- ->with($this->equalTo($types));
165
-
166
- $setCacheStatusMethod->invoke($controller, ['block_html', 'test'], $status);
167
- }
168
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Prod/DevModeTest.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
-
3
- class Ecocode_Profiler_Tests_DevModeTest
4
- extends TestHelper
5
- {
6
-
7
-
8
- public function testDisabledInProduction()
9
- {
10
- $app = Mage::app();
11
-
12
- $this->assertNotInstanceOf(
13
- 'Ecocode_Profiler_Model_AppDev',
14
- $app
15
- );
16
- }
17
-
18
- public function testCollectorsNotLoaded()
19
- {
20
- $app = Mage::app();
21
-
22
- $value = $app->getConfig()->getNode('ecocode/profiler');
23
- $this->assertFalse($value);
24
- }
25
-
26
- public function testModelsNotLoaded()
27
- {
28
- $app = Mage::app();
29
-
30
- $value = $app->getConfig()->getNode('global/models/ecocode_profiler');
31
- $this->assertFalse($value);
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/Prod/bootstrap.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
-
3
- if (isset($_SERVER['MAGENTO_DIRECTORY'])) {
4
- $_baseDir = $_SERVER['MAGENTO_DIRECTORY'];
5
- } else {
6
- $_baseDir = getcwd();
7
- }
8
-
9
- /**
10
- * Define MAGE_PATH
11
- * Path to Magento
12
- */
13
- define('MAGENTO_ROOT', $_baseDir);
14
-
15
- // Include Mage file by detecting app root
16
- require_once $_baseDir . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';
17
-
18
- if (!Mage::isInstalled()) {
19
- throw new RuntimeException('Magento Unit Tests can run only on installed version');
20
- }
21
-
22
-
23
- /* Replace server variables for proper file naming */
24
- $_SERVER['SCRIPT_NAME'] = $_baseDir . DS . 'index.php';
25
- $_SERVER['SCRIPT_FILENAME'] = $_baseDir . DS . 'index.php';
26
-
27
-
28
- //flag to check for unittets
29
- define('BASE_TESTS_PATH', realpath(dirname(__FILE__)));
30
- require_once BASE_TESTS_PATH . '/../TestHelper.php';
31
-
32
- $options = [
33
- 'cache' => ['id_prefix' => 'test-prod']
34
- ];
35
- Mage::app()->cleanCache();
36
- Mage::app('', 'store', $options);
37
- // Removing Varien Autoload, to prevent errors with PHPUnit components
38
- spl_autoload_unregister([\Varien_Autoload::instance(), 'autoload']);
39
- spl_autoload_register(function ($className) {
40
- $filePath = strtr(
41
- ltrim($className, '\\'),
42
- [
43
- '\\' => '/',
44
- '_' => '/'
45
- ]
46
- );
47
- $file = $filePath . '.php';
48
- if (stream_resolve_include_path($file)) {
49
- include $filePath . '.php';
50
- }
51
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/Tests/TestHelper.php DELETED
@@ -1,91 +0,0 @@
1
- <?php
2
-
3
- class TestHelper extends PHPUnit_Framework_TestCase
4
- {
5
- protected static $mageAppReflection;
6
-
7
- protected $reInetMage = false;
8
-
9
- protected $mageDefaultProperties = [
10
- '_registry' => [],
11
- '_isDownloader' => false,
12
- '_isDeveloperMode' => false,
13
- 'headersSentThrowsException' => true,
14
- ];
15
-
16
- /**
17
- * @beforeClass
18
- */
19
- protected function setUp()
20
- {
21
- $this->initAppOnMageClass($this->reInetMage);
22
- }
23
-
24
- public function resetMage()
25
- {
26
- if (!isset($this->mageDefaultProperties['_appRoot'])) {
27
- //save to original mage root
28
- $this->mageDefaultProperties['_appRoot'] = Mage::getRoot();
29
- }
30
- $mageReflectionClass = new \ReflectionClass('Mage');
31
- $properties = $mageReflectionClass->getStaticProperties();
32
-
33
- foreach($properties as $key => $value) {
34
- $reflectedProperty = $mageReflectionClass->getProperty($key);
35
- $reflectedProperty->setAccessible(true);
36
- $value = null;
37
- if (isset($this->mageDefaultProperties[$key])) {
38
- $value = $this->mageDefaultProperties[$key];
39
- }
40
- $reflectedProperty->setValue($value);
41
- }
42
- $this->initApp();
43
- }
44
-
45
- public function initAppOnMageClass($force = false)
46
- {
47
- $mageReflectionClass = new \ReflectionClass('Mage');
48
-
49
- if ($force) {
50
- $reflectedProperty = $mageReflectionClass->getProperty('_app');
51
- $reflectedProperty->setAccessible(true);
52
- $reflectedProperty->setValue(null);
53
- }
54
- $this->initApp();
55
- }
56
-
57
- protected function initApp(Mage_Core_Model_App $app = null)
58
- {
59
- $options = [
60
- 'cache' => ['id_prefix' => 'dev-test'],
61
- 'config_model' => 'Ecocode_Profiler_Model_Core_Config'
62
- ];
63
- if ($app) {
64
- $app->init('', 'store', $options);
65
- } else {
66
- Mage::app('', 'store', $options);
67
- }
68
-
69
- }
70
-
71
- /**
72
- * @param $data
73
- * @return Varien_Event_Observer
74
- */
75
- protected function getObserver($data)
76
- {
77
- $observer = new Varien_Event_Observer();
78
- $event = new Varien_Event($data);
79
- $observer->setEvent($event);
80
-
81
- return $observer;
82
- }
83
-
84
- public function getProtectedValue($object, $property)
85
- {
86
- $property = new ReflectionProperty(get_class($object), $property);
87
- $property->setAccessible(true);
88
-
89
- return $property->getValue($object);
90
- }
91
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ecocode/Profiler/autoloader.php CHANGED
@@ -5,23 +5,27 @@ class Ecocode_Profiler_Autoloader
5
  {
6
  public static $autoloader;
7
 
8
- /** @var Closure */
9
  protected $includeFile;
10
  protected $classMap = [];
11
 
12
-
 
 
 
13
  public static function getAutoloader()
14
  {
15
  if (self::$autoloader === null) {
16
  self::$autoloader = new Ecocode_Profiler_Autoloader();
17
  }
 
18
  return self::$autoloader;
19
  }
20
 
21
  /**
22
  * Registers this instance as an autoloader.
23
- *
24
  * @param bool $prepend Whether to prepend the autoloader or not
 
25
  */
26
  public function register($prepend = false)
27
  {
@@ -30,6 +34,7 @@ class Ecocode_Profiler_Autoloader
30
 
31
  /**
32
  * Unregisters this instance as an autoloader.
 
33
  */
34
  public function unregister()
35
  {
@@ -50,8 +55,11 @@ class Ecocode_Profiler_Autoloader
50
  include $file;
51
  };
52
  $includeFile($this->classMap[$class]);
 
53
  return true;
54
  }
 
 
55
  }
56
 
57
  public function addOverwrite($className, $file)
@@ -60,6 +68,15 @@ class Ecocode_Profiler_Autoloader
60
  $overwriteDir = __DIR__ . DIRECTORY_SEPARATOR . 'overwrite' . DIRECTORY_SEPARATOR;
61
  $file = $overwriteDir . $file;
62
  }
 
 
 
 
 
 
 
 
 
63
  $this->classMap[$className] = $file;
64
 
65
  return $this;
5
  {
6
  public static $autoloader;
7
 
8
+ /** @var Closure */
9
  protected $includeFile;
10
  protected $classMap = [];
11
 
12
+ /**
13
+ * @codeCoverageIgnore
14
+ * @return Ecocode_Profiler_Autoloader
15
+ */
16
  public static function getAutoloader()
17
  {
18
  if (self::$autoloader === null) {
19
  self::$autoloader = new Ecocode_Profiler_Autoloader();
20
  }
21
+
22
  return self::$autoloader;
23
  }
24
 
25
  /**
26
  * Registers this instance as an autoloader.
 
27
  * @param bool $prepend Whether to prepend the autoloader or not
28
+ * @codeCoverageIgnore
29
  */
30
  public function register($prepend = false)
31
  {
34
 
35
  /**
36
  * Unregisters this instance as an autoloader.
37
+ * @codeCoverageIgnore
38
  */
39
  public function unregister()
40
  {
55
  include $file;
56
  };
57
  $includeFile($this->classMap[$class]);
58
+
59
  return true;
60
  }
61
+
62
+ return false;
63
  }
64
 
65
  public function addOverwrite($className, $file)
68
  $overwriteDir = __DIR__ . DIRECTORY_SEPARATOR . 'overwrite' . DIRECTORY_SEPARATOR;
69
  $file = $overwriteDir . $file;
70
  }
71
+
72
+ $this->addToClassMap($className, $file);
73
+
74
+
75
+ return $this;
76
+ }
77
+
78
+ public function addToClassMap($className, $file)
79
+ {
80
  $this->classMap[$className] = $file;
81
 
82
  return $this;
app/code/community/Ecocode/Profiler/controllers/IndexController.php CHANGED
@@ -8,9 +8,6 @@ class Ecocode_Profiler_IndexController extends Ecocode_Profiler_Controller_Abstr
8
  $this->renderLayout();
9
  }
10
 
11
- /**
12
- *
13
- */
14
  public function toolbarAction()
15
  {
16
  $token = $this->getRequest()->getParam(Ecocode_Profiler_Model_Profiler::URL_TOKEN_PARAMETER);
@@ -25,6 +22,7 @@ class Ecocode_Profiler_IndexController extends Ecocode_Profiler_Controller_Abstr
25
 
26
  public function searchAction()
27
  {
 
28
  $request = $this->getRequest();
29
 
30
  $ip = preg_replace('/[^:\d\.]/', '', $request->getParam('ip'));
@@ -35,14 +33,15 @@ class Ecocode_Profiler_IndexController extends Ecocode_Profiler_Controller_Abstr
35
  $limit = $request->getParam('limit');
36
  $token = $request->getParam('_token');
37
 
38
- if (null !== $session = Mage::getSingleton('core/session')) {
39
- $session->setData('_profiler_search_ip', $ip);
40
- $session->setData('_profiler_search_method', $method);
41
- $session->setData('_profiler_search_url', $url);
42
- $session->setData('_profiler_search_start', $start);
43
- $session->setData('_profiler_search_end', $end);
44
- $session->setData('_profiler_search_limit', $limit);
45
- $session->setData('_profiler_search_token', $token);
 
46
  }
47
 
48
  if (!empty($token)) {
@@ -63,6 +62,7 @@ class Ecocode_Profiler_IndexController extends Ecocode_Profiler_Controller_Abstr
63
 
64
  public function searchResultsAction()
65
  {
 
66
  $request = $this->getRequest();
67
  $profiler = $this->getProfiler();
68
 
@@ -148,6 +148,9 @@ class Ecocode_Profiler_IndexController extends Ecocode_Profiler_Controller_Abstr
148
  return $this->renderLayout();
149
  }
150
 
 
 
 
151
  public function phpinfoAction()
152
  {
153
  phpinfo();
8
  $this->renderLayout();
9
  }
10
 
 
 
 
11
  public function toolbarAction()
12
  {
13
  $token = $this->getRequest()->getParam(Ecocode_Profiler_Model_Profiler::URL_TOKEN_PARAMETER);
22
 
23
  public function searchAction()
24
  {
25
+ /** @var Mage_Core_Controller_Request_Http$request */
26
  $request = $this->getRequest();
27
 
28
  $ip = preg_replace('/[^:\d\.]/', '', $request->getParam('ip'));
33
  $limit = $request->getParam('limit');
34
  $token = $request->getParam('_token');
35
 
36
+ if ($session = Mage::getSingleton('ecocode_profiler/session')) {
37
+ /** @var Ecocode_Profiler_Model_Session $session */
38
+ $session->setData('search_ip', $ip);
39
+ $session->setData('search_method', $method);
40
+ $session->setData('search_url', $url);
41
+ $session->setData('search_start', $start);
42
+ $session->setData('search_end', $end);
43
+ $session->setData('search_limit', $limit);
44
+ $session->setData('search_token', $token);
45
  }
46
 
47
  if (!empty($token)) {
62
 
63
  public function searchResultsAction()
64
  {
65
+ /** @var Mage_Core_Controller_Request_Http$request */
66
  $request = $this->getRequest();
67
  $profiler = $this->getProfiler();
68
 
148
  return $this->renderLayout();
149
  }
150
 
151
+ /**
152
+ * @codeCoverageIgnore
153
+ */
154
  public function phpinfoAction()
155
  {
156
  phpinfo();
app/code/community/Ecocode/Profiler/debug.php CHANGED
@@ -3,7 +3,7 @@ use Symfony\Component\Debug\BufferingLogger;
3
  use Symfony\Component\Debug\Debug;
4
  use Symfony\Component\Debug\ErrorHandler;
5
 
6
- if (class_exists('\Symfony\Component\Debug\Debug')) {
7
  class MagentoErrorHandler extends ErrorHandler
8
  {
9
  public function handleException($exception, array $error = null)
3
  use Symfony\Component\Debug\Debug;
4
  use Symfony\Component\Debug\ErrorHandler;
5
 
6
+ if (@class_exists('\Symfony\Component\Debug\Debug')) {
7
  class MagentoErrorHandler extends ErrorHandler
8
  {
9
  public function handleException($exception, array $error = null)
app/code/community/Ecocode/Profiler/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Ecocode_Profiler>
5
- <version>1.1.0</version>
6
  </Ecocode_Profiler>
7
  </modules>
8
  </config>
2
  <config>
3
  <modules>
4
  <Ecocode_Profiler>
5
+ <version>1.2.0</version>
6
  </Ecocode_Profiler>
7
  </modules>
8
  </config>
app/code/community/Ecocode/Profiler/etc/development.xml CHANGED
@@ -61,6 +61,20 @@
61
  </profiler>
62
  </routers>
63
  <events>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  <controller_front_send_response_before>
65
  <observers>
66
  <ecocode_profiler>
61
  </profiler>
62
  </routers>
63
  <events>
64
+ <controller_action_predispatch>
65
+ <observers>
66
+ <ecocode_profiler_check_redirect>
67
+ <type>singleton</type>
68
+ <class>ecocode_profiler/observer</class>
69
+ <method>checkRedirect</method>
70
+ </ecocode_profiler_check_redirect>
71
+ <ecocode_profiler_capture_flash_messages>
72
+ <type>singleton</type>
73
+ <class>ecocode_profiler/observer</class>
74
+ <method>captureFlashMessages</method>
75
+ </ecocode_profiler_capture_flash_messages>
76
+ </observers>
77
+ </controller_action_predispatch>
78
  <controller_front_send_response_before>
79
  <observers>
80
  <ecocode_profiler>
app/code/community/Ecocode/Profiler/overwrite/Mage.php CHANGED
@@ -28,16 +28,17 @@ if (!file_exists($mageCacheFile)) {
28
 
29
  file_put_contents($mageCacheFile, $mageCode);
30
  }
31
-
32
- require_once $mageCacheFile;
 
33
 
34
 
35
  class Mage extends MageOriginal
36
  {
37
- protected static $_logChannels = [];
38
 
39
- protected static $_logger;
40
- protected static $_loggerDebugHandler;
41
 
42
  /**
43
  * @return Ecocode_Profiler_Model_Logger
@@ -47,34 +48,35 @@ class Mage extends MageOriginal
47
  if ($channel === null) {
48
  return static::getDefaultLogger();
49
  }
50
- if (!isset(static::$_logChannels[$channel])) {
51
- static::$_logChannels[$channel] = static::getNewLogger($channel);
52
  }
53
 
54
- return static::$_logChannels[$channel];
55
  }
56
 
57
  public static function getDefaultLogger()
58
  {
59
- if (static::$_logger === null) {
60
- static::$_logger = static::getNewLogger('default');
61
  }
62
 
63
- return static::$_logger;
64
  }
65
 
66
  protected static function getNewLogger($channel)
67
  {
68
  if (!@class_exists('\Monolog\Logger')) {
69
- return false;
70
  }
71
- if (static::$_loggerDebugHandler === null) {
72
- static::$_loggerDebugHandler = new Ecocode_Profiler_Model_Logger_DebugHandler();
 
73
  }
74
 
75
  return new Ecocode_Profiler_Model_Logger(
76
  $channel,
77
- [static::$_loggerDebugHandler]
78
  );
79
  }
80
 
28
 
29
  file_put_contents($mageCacheFile, $mageCode);
30
  }
31
+ //register overwrite
32
+ Ecocode_Profiler_Autoloader::getAutoloader()
33
+ ->addToClassMap('MageOriginal', $mageCacheFile);
34
 
35
 
36
  class Mage extends MageOriginal
37
  {
38
+ protected static $logChannels = [];
39
 
40
+ protected static $logger;
41
+ protected static $loggerDebugHandler;
42
 
43
  /**
44
  * @return Ecocode_Profiler_Model_Logger
48
  if ($channel === null) {
49
  return static::getDefaultLogger();
50
  }
51
+ if (!isset(static::$logChannels[$channel])) {
52
+ static::$logChannels[$channel] = static::getNewLogger($channel);
53
  }
54
 
55
+ return static::$logChannels[$channel];
56
  }
57
 
58
  public static function getDefaultLogger()
59
  {
60
+ if (static::$logger === null) {
61
+ static::$logger = static::getNewLogger('default');
62
  }
63
 
64
+ return static::$logger;
65
  }
66
 
67
  protected static function getNewLogger($channel)
68
  {
69
  if (!@class_exists('\Monolog\Logger')) {
70
+ return new Ecocode_Profiler_Model_NullLogger();
71
  }
72
+
73
+ if (static::$loggerDebugHandler === null) {
74
+ static::$loggerDebugHandler = new Ecocode_Profiler_Model_Logger_DebugHandler();
75
  }
76
 
77
  return new Ecocode_Profiler_Model_Logger(
78
  $channel,
79
+ [static::$loggerDebugHandler]
80
  );
81
  }
82
 
app/code/community/Ecocode/Profiler/overwrite/MageCoreModelStore.php CHANGED
@@ -11,6 +11,7 @@ class Mage_Core_Model_Store extends
11
  /**
12
  * Remove script file name from url in case when server rewrites are enabled
13
  *
 
14
  * @param string $url
15
  * @return string
16
  */
11
  /**
12
  * Remove script file name from url in case when server rewrites are enabled
13
  *
14
+ * @SuppressWarnings("superglobals")
15
  * @param string $url
16
  * @return string
17
  */
app/code/community/Ecocode/Profiler/overwrite/MageCoreModelTranslate.php CHANGED
@@ -20,14 +20,14 @@ class Mage_Core_Model_Translate extends Original_Mage_Core_Model_Translate
20
 
21
  public function translate($args)
22
  {
23
- $_args = $args;
24
  $this->currentMessage = [
25
  'locale' => $this->_locale,
26
  'module' => null,
27
  'trace' => []
28
  ];
29
 
30
- $text = array_shift($_args);
31
 
32
  if ($text instanceof Mage_Core_Model_Translate_Expr) {
33
  $this->currentMessage['module'] = $text->getModule();
@@ -39,7 +39,7 @@ class Mage_Core_Model_Translate extends Original_Mage_Core_Model_Translate
39
  return $translation;
40
  }
41
 
42
- if (@vsprintf($this->currentMessage['translation'], $_args) === false) {
43
  $trace = $this->addTrace();
44
  if ($trace && $this->traceHasFunctionCall($trace, 'getTranslateJson')) {
45
  //dont log invalid as strings are used with empty placeholders is intended here
@@ -48,7 +48,7 @@ class Mage_Core_Model_Translate extends Original_Mage_Core_Model_Translate
48
  }
49
  }
50
 
51
- $this->currentMessage['parameters'] = $_args;
52
  $this->currentMessage['translation'] = $translation;
53
 
54
  $this->log();
@@ -101,6 +101,7 @@ class Mage_Core_Model_Translate extends Original_Mage_Core_Model_Translate
101
  *
102
  * @param array $data
103
  * @param string $scope
 
104
  * @return Mage_Core_Model_Translate
105
  */
106
  protected function _addData($data, $scope, $forceReload = false)
@@ -128,13 +129,13 @@ class Mage_Core_Model_Translate extends Original_Mage_Core_Model_Translate
128
  */
129
  protected function addTrace()
130
  {
131
- $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
132
 
133
  while (($trace = reset($backtrace)) && (!isset($trace['function']) || $trace['function'] !== '__')) {
134
  array_shift($backtrace);
135
  }
136
 
137
- return $this->currentMessage['trace'] = array_slice($backtrace, 0, 5);
138
  }
139
 
140
  /**
20
 
21
  public function translate($args)
22
  {
23
+ $argsCopy = $args;
24
  $this->currentMessage = [
25
  'locale' => $this->_locale,
26
  'module' => null,
27
  'trace' => []
28
  ];
29
 
30
+ $text = array_shift($argsCopy);
31
 
32
  if ($text instanceof Mage_Core_Model_Translate_Expr) {
33
  $this->currentMessage['module'] = $text->getModule();
39
  return $translation;
40
  }
41
 
42
+ if (@vsprintf($this->currentMessage['translation'], $argsCopy) === false) {
43
  $trace = $this->addTrace();
44
  if ($trace && $this->traceHasFunctionCall($trace, 'getTranslateJson')) {
45
  //dont log invalid as strings are used with empty placeholders is intended here
48
  }
49
  }
50
 
51
+ $this->currentMessage['parameters'] = $argsCopy;
52
  $this->currentMessage['translation'] = $translation;
53
 
54
  $this->log();
101
  *
102
  * @param array $data
103
  * @param string $scope
104
+ * @param bool $forceReload
105
  * @return Mage_Core_Model_Translate
106
  */
107
  protected function _addData($data, $scope, $forceReload = false)
129
  */
130
  protected function addTrace()
131
  {
132
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20);
133
 
134
  while (($trace = reset($backtrace)) && (!isset($trace['function']) || $trace['function'] !== '__')) {
135
  array_shift($backtrace);
136
  }
137
 
138
+ return $this->currentMessage['trace'] = array_slice($backtrace, 0, 10);
139
  }
140
 
141
  /**
app/design/frontend/base/default/layout/ecocode_profiler.xml CHANGED
@@ -33,7 +33,7 @@
33
  <profiler_index_toolbar>
34
  <block type="ecocode_profiler/toolbar" name="root" output="toHtml" template="ecocode_profiler/toolbar.phtml">
35
  <block name="profiler.mysql.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/mysql/toolbar.phtml"/>
36
- <block name="profiler.request.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/request/toolbar.phtml"/>
37
  <block name="profiler.time.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/time/toolbar.phtml"/>
38
  <block name="profiler.translation.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/translation/toolbar.phtml"/>
39
  <block name="profiler.ajax.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/ajax/toolbar.phtml"/>
33
  <profiler_index_toolbar>
34
  <block type="ecocode_profiler/toolbar" name="root" output="toHtml" template="ecocode_profiler/toolbar.phtml">
35
  <block name="profiler.mysql.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/mysql/toolbar.phtml"/>
36
+ <block name="profiler.request.toolbar" type="ecocode_profiler/collector_request_toolbar" template="ecocode_profiler/collector/request/toolbar.phtml"/>
37
  <block name="profiler.time.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/time/toolbar.phtml"/>
38
  <block name="profiler.translation.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/translation/toolbar.phtml"/>
39
  <block name="profiler.ajax.toolbar" type="ecocode_profiler/collector_base" template="ecocode_profiler/collector/ajax/toolbar.phtml"/>
app/design/frontend/base/default/template/ecocode_profiler/collector/cache/toolbar.phtml CHANGED
@@ -33,14 +33,14 @@ $cacheTypes = Mage::app()->getCacheInstance()->getTypes();
33
  <?php if ($currentStatus): ?>
34
  <a href="#"
35
  data-url="<?php echo Mage::getUrl('_profiler/cache/clear', ['types' => $cache['id']]) ?>"
36
- class="btn btn-sm ajax-action">Clear</a> /
37
  <a href="#"
38
  data-url="<?php echo Mage::getUrl('_profiler/cache/disable', ['types' => $cache['id']]) ?>"
39
- class="btn btn-sm ajax-action">Disable</a>
40
  <?php else: ?>
41
  <a href="#"
42
  data-url="<?php echo Mage::getUrl('_profiler/cache/enable', ['types' => $cache['id']]) ?>"
43
- class="btn btn-sm ajax-action">Enable</a>
44
  <?php endif; ?>
45
  </div>
46
  <?php endforeach; ?>
@@ -59,4 +59,4 @@ $cacheTypes = Mage::app()->getCacheInstance()->getTypes();
59
 
60
  </div>
61
 
62
- </div>
33
  <?php if ($currentStatus): ?>
34
  <a href="#"
35
  data-url="<?php echo Mage::getUrl('_profiler/cache/clear', ['types' => $cache['id']]) ?>"
36
+ class="ajax-action">Clear</a> /
37
  <a href="#"
38
  data-url="<?php echo Mage::getUrl('_profiler/cache/disable', ['types' => $cache['id']]) ?>"
39
+ class="ajax-action">Disable</a>
40
  <?php else: ?>
41
  <a href="#"
42
  data-url="<?php echo Mage::getUrl('_profiler/cache/enable', ['types' => $cache['id']]) ?>"
43
+ class="ajax-action">Enable</a>
44
  <?php endif; ?>
45
  </div>
46
  <?php endforeach; ?>
59
 
60
  </div>
61
 
62
+ </div>
app/design/frontend/base/default/template/ecocode_profiler/collector/log/panel/log-table.phtml CHANGED
@@ -9,6 +9,9 @@ $codeHelper = Mage::helper('ecocode_profiler/code');
9
 
10
  /** @var Ecocode_Profiler_Helper_ValueExporter $valueExporter */
11
  $valueExporter = Mage::helper('ecocode_profiler/valueExporter');
 
 
 
12
  ?>
13
  <table class="logs" xmlns="http://www.w3.org/1999/html">
14
  <thead>
@@ -56,48 +59,18 @@ $valueExporter = Mage::helper('ecocode_profiler/valueExporter');
56
  <?php if ($this->isDeprecation()): ?>
57
  <?php $stack = isset($log['context']['stack']) ? $log['context']['stack'] : []; ?>
58
  <?php array_shift($stack); //remove the error handler from stack ?>
59
- <?php $stackId = 'sf-call-stack-' . $this->getCategory() . '-' . $index; ?>
60
 
61
  <?php if (isset($log['context']['errorCount'])): ?>
62
  <span class="text-small text-bold">(<?php echo $log['context']['errorCount'] ?> times)</span>
63
  <?php endif; ?>
64
 
65
  <?php if ($stack): ?>
66
- <button class="btn-link text-small sf-toggle" data-toggle-selector="#<?php echo $stackId ?>"
67
  data-toggle-alt-content="Hide stack trace">Show stack trace
68
  </button>
 
69
  <?php endif; ?>
70
-
71
- <ul class="sf-call-stack hidden" id="<?php echo $stackId ?>">
72
- <?php foreach ($stack as $index => $call): ?>
73
- <?php
74
- $from = '-';
75
- if (isset($call['class'])) {
76
- $from = $codeHelper->abbrClass($call['class']) . '::' . $codeHelper->abbrMethod($call['function']);
77
- } elseif (isset($call['function'])) {
78
- $from = $codeHelper->abbrMethod($call['function']);
79
- } elseif (isset($call['file'])) {
80
- $from = $call['file'];
81
- }
82
-
83
- $fileName = null;
84
- if (isset($call['file'], $call['line'])) {
85
- $fileName = str_replace('\\', '/', $call['file']);
86
- $fileName = explode('/', $fileName);
87
- $fileName = end($fileName);
88
- }
89
- ?>
90
-
91
- <li>
92
- <?php echo $from; ?>
93
- <?php if ($fileName): ?>
94
- <span
95
- class="text-small">(called from <?php echo $codeHelper->formatFile($call['file'], $call['line'], $fileName) ?>
96
- )</span>
97
- <?php endif; ?>
98
- </li>
99
- <?php endforeach; ?>
100
- </ul>
101
  <?php else: ?>
102
  <?php if (!empty($log['context'])): ?>
103
  <?php $contextId = 'context-' . $this->getCategory() . '-' . $index; ?>
9
 
10
  /** @var Ecocode_Profiler_Helper_ValueExporter $valueExporter */
11
  $valueExporter = Mage::helper('ecocode_profiler/valueExporter');
12
+
13
+ /** @var Ecocode_Profiler_Helper_Renderer $rendererHelper */
14
+ $rendererHelper = Mage::helper('ecocode_profiler/renderer');
15
  ?>
16
  <table class="logs" xmlns="http://www.w3.org/1999/html">
17
  <thead>
59
  <?php if ($this->isDeprecation()): ?>
60
  <?php $stack = isset($log['context']['stack']) ? $log['context']['stack'] : []; ?>
61
  <?php array_shift($stack); //remove the error handler from stack ?>
62
+ <?php $stackId = $this->getCategory() . '-' . $index; ?>
63
 
64
  <?php if (isset($log['context']['errorCount'])): ?>
65
  <span class="text-small text-bold">(<?php echo $log['context']['errorCount'] ?> times)</span>
66
  <?php endif; ?>
67
 
68
  <?php if ($stack): ?>
69
+ <button class="btn-link text-small sf-toggle" data-toggle-selector="#stack-<?php echo $stackId ?>"
70
  data-toggle-alt-content="Hide stack trace">Show stack trace
71
  </button>
72
+ <?php echo $rendererHelper->renderCallStack($stackId, $stack) ?>
73
  <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  <?php else: ?>
75
  <?php if (!empty($log['context'])): ?>
76
  <?php $contextId = 'context-' . $this->getCategory() . '-' . $index; ?>
app/design/frontend/base/default/template/ecocode_profiler/collector/model/panel.phtml CHANGED
@@ -71,7 +71,7 @@ $rendererHelper = Mage::helper('ecocode_profiler/renderer');
71
  <?php endif; ?>
72
  </div>
73
  <?php if (isset($log['trace'])): ?>
74
- <?php echo $rendererHelper->renderBackTrace($prefix . $index, $log['trace']) ?>
75
  <?php endif; ?>
76
  </td>
77
  </tr>
@@ -125,7 +125,7 @@ $rendererHelper = Mage::helper('ecocode_profiler/renderer');
125
  <?php endif; ?>
126
  </div>
127
  <?php if (isset($log['trace'])): ?>
128
- <?php echo $rendererHelper->renderBackTrace($prefix . $index, $log['trace']) ?>
129
  <?php endif; ?>
130
  </td>
131
  </tr>
71
  <?php endif; ?>
72
  </div>
73
  <?php if (isset($log['trace'])): ?>
74
+ <?php echo $rendererHelper->renderCallStack($prefix . $index, $log['trace']) ?>
75
  <?php endif; ?>
76
  </td>
77
  </tr>
125
  <?php endif; ?>
126
  </div>
127
  <?php if (isset($log['trace'])): ?>
128
+ <?php echo $rendererHelper->renderCallStack($prefix . $index, $log['trace']) ?>
129
  <?php endif; ?>
130
  </td>
131
  </tr>
app/design/frontend/base/default/template/ecocode_profiler/collector/mysql/menu.phtml CHANGED
@@ -5,15 +5,16 @@ $collector = $this->getCollector();
5
 
6
  <span class="label <?php echo $collector->getQueryCount() == 0 ? 'disabled' : '' ?>">
7
  <span class="icon">
8
- <svg version="1.1"xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" height="24" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
9
  <path fill="#AAAAAA" d="M5,8h14c1.7,0,3-1.3,3-3s-1.3-3-3-3H5C3.3,2,2,3.3,2,5S3.3,8,5,8z M18,3.6c0.8,0,1.5,0.7,1.5,1.5S18.8,6.6,18,6.6s-1.5-0.7-1.5-1.5S17.2,3.6,18,3.6z M19,9H5c-1.7,0-3,1.3-3,3s1.3,3,3,3h14c1.7,0,3-1.3,3-3S20.7,9,19,9z M18,13.6
10
  c-0.8,0-1.5-0.7-1.5-1.5s0.7-1.5,1.5-1.5s1.5,0.7,1.5,1.5S18.8,13.6,18,13.6z M19,16H5c-1.7,0-3,1.3-3,3s1.3,3,3,3h14c1.7,0,3-1.3,3-3S20.7,16,19,16z M18,20.6c-0.8,0-1.5-0.7-1.5-1.5s0.7-1.5,1.5-1.5s1.5,0.7,1.5,1.5S18.8,20.6,18,20.6z"/>
11
  </svg>
12
  </span>
13
  <strong>Mysql</strong>
14
- <!-- {% if collector.invalidEntityCount %}
15
- <span class="count">
16
- <span>{{ collector.invalidEntityCount }}</span>
 
17
  </span>
18
- {% endif %}-->
19
- </span>
5
 
6
  <span class="label <?php echo $collector->getQueryCount() == 0 ? 'disabled' : '' ?>">
7
  <span class="icon">
8
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" height="24" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
9
  <path fill="#AAAAAA" d="M5,8h14c1.7,0,3-1.3,3-3s-1.3-3-3-3H5C3.3,2,2,3.3,2,5S3.3,8,5,8z M18,3.6c0.8,0,1.5,0.7,1.5,1.5S18.8,6.6,18,6.6s-1.5-0.7-1.5-1.5S17.2,3.6,18,3.6z M19,9H5c-1.7,0-3,1.3-3,3s1.3,3,3,3h14c1.7,0,3-1.3,3-3S20.7,9,19,9z M18,13.6
10
  c-0.8,0-1.5-0.7-1.5-1.5s0.7-1.5,1.5-1.5s1.5,0.7,1.5,1.5S18.8,13.6,18,13.6z M19,16H5c-1.7,0-3,1.3-3,3s1.3,3,3,3h14c1.7,0,3-1.3,3-3S20.7,16,19,16z M18,20.6c-0.8,0-1.5-0.7-1.5-1.5s0.7-1.5,1.5-1.5s1.5,0.7,1.5,1.5S18.8,20.6,18,20.6z"/>
11
  </svg>
12
  </span>
13
  <strong>Mysql</strong>
14
+ <span class="count">
15
+ <span>
16
+ <?php echo$collector->getQueryCount()?> /
17
+ <?php echo sprintf('%0.2f', $collector->getTotalTime() * 1000) ?> ms
18
  </span>
19
+ </span>
20
+ </span>
app/design/frontend/base/default/template/ecocode_profiler/collector/mysql/panel.phtml CHANGED
@@ -6,9 +6,12 @@ $collector = $this->getCollector();
6
  $identicalQueries = $this->getIdenticalQueries();
7
  $identicalQueriesCount = count($identicalQueries);
8
 
9
- $queriesByContext = $this->getByContext();
10
- $contextHelper = Mage::helper('ecocode_profiler/context');
11
- $queryTableRenderer = $this->getQueryTableRenderer();
 
 
 
12
  ?>
13
 
14
 
@@ -197,18 +200,7 @@ $queryTableRenderer = $this->getQueryTableRenderer();
197
  <tr>
198
  <td class="nowrap">#<?php echo $j + 1 ?></td>
199
  <td>
200
- <ul class="sf-call-stack ">
201
- <?php foreach ($trace as $item): ?>
202
- <li>
203
- <?php echo isset($item['class']) ? $item['class'] : '' ?>
204
- ::<?php echo $item['function'] ?><br>
205
- <?php if (isset($item['file'])): ?>
206
- <small><?php echo $item['file'] ?>
207
- ::<?php echo $item['line'] ?></small>
208
- <?php endif; ?>
209
- </li>
210
- <?php endforeach; ?>
211
- </ul>
212
  </td>
213
  </tr>
214
  <?php endforeach; ?>
@@ -262,15 +254,17 @@ $queryTableRenderer = $this->getQueryTableRenderer();
262
  </script>
263
  <style>
264
  <?php foreach ($connections as $name => $queryCount): ?>
265
- #all-queries[data-connection="<?php echo $name ?>"] tbody > tr:not([data-connection="<?php echo $name ?>"]) {
266
- display: none;
267
- }
 
268
  <?php endforeach; ?>
269
 
270
  <?php foreach ($this->getQueryCountByType() as $name => $queryCount): ?>
271
- #all-queries[data-type="<?php echo $name ?>"] tbody > tr:not([data-type="<?php echo $name ?>"]) {
272
- display: none;
273
- }
 
274
  <?php endforeach; ?>
275
 
276
  #all-queries span[data-toggle="query-type"],
6
  $identicalQueries = $this->getIdenticalQueries();
7
  $identicalQueriesCount = count($identicalQueries);
8
 
9
+ $queriesByContext = $this->getByContext();
10
+ $contextHelper = Mage::helper('ecocode_profiler/context');
11
+ $queryTableRenderer = $this->getQueryTableRenderer();
12
+
13
+ /** @var Ecocode_Profiler_Helper_Renderer $rendererHelper */
14
+ $rendererHelper = Mage::helper('ecocode_profiler/renderer');
15
  ?>
16
 
17
 
200
  <tr>
201
  <td class="nowrap">#<?php echo $j + 1 ?></td>
202
  <td>
203
+ <?php echo $rendererHelper->renderCallStack($j + 1, $trace, false) ?>
 
 
 
 
 
 
 
 
 
 
 
204
  </td>
205
  </tr>
206
  <?php endforeach; ?>
254
  </script>
255
  <style>
256
  <?php foreach ($connections as $name => $queryCount): ?>
257
+ #all-queries[data-connection="<?php echo $name ?>"] tbody > tr:not([data-connection="<?php echo $name ?>"]) {
258
+ display: none;
259
+ }
260
+
261
  <?php endforeach; ?>
262
 
263
  <?php foreach ($this->getQueryCountByType() as $name => $queryCount): ?>
264
+ #all-queries[data-type="<?php echo $name ?>"] tbody > tr:not([data-type="<?php echo $name ?>"]) {
265
+ display: none;
266
+ }
267
+
268
  <?php endforeach; ?>
269
 
270
  #all-queries span[data-toggle="query-type"],
app/design/frontend/base/default/template/ecocode_profiler/collector/mysql/panel/query-table.phtml CHANGED
@@ -16,7 +16,7 @@ $rendererHelper = Mage::helper('ecocode_profiler/renderer');
16
  </thead>
17
  <tbody>
18
  <?php foreach ($this->getData('queries') as $index => $queryData): ?>
19
- <tr data-type="<?php echo $queryData['type']?>" data-connection="<?php echo $queryData['connection'] ?>">
20
  <td class="nowrap"><?php echo $index + 1 ?> </td>
21
  <td class="nowrap"><?php echo $queryData['connection'] ?> </td>
22
  <td class="nowrap"><?php echo sprintf('%0.2f', $queryData['time'] * 1000) ?> ms</td>
@@ -28,7 +28,7 @@ $rendererHelper = Mage::helper('ecocode_profiler/renderer');
28
 
29
  </div>
30
  <div>
31
- <?php echo $contextHelper->render($prefix, $queryData['context']); ?>
32
  </div>
33
 
34
  <div class="text-small font-normal">
@@ -54,7 +54,7 @@ $rendererHelper = Mage::helper('ecocode_profiler/renderer');
54
  </div>
55
 
56
  <?php if (isset($queryData['trace'])): ?>
57
- <?php echo $rendererHelper->renderBackTrace($prefix . $index, $queryData['trace']) ?>
58
  <?php endif; ?>
59
  </td>
60
  </tr>
16
  </thead>
17
  <tbody>
18
  <?php foreach ($this->getData('queries') as $index => $queryData): ?>
19
+ <tr data-type="<?php echo $queryData['type'] ?>" data-connection="<?php echo $queryData['connection'] ?>">
20
  <td class="nowrap"><?php echo $index + 1 ?> </td>
21
  <td class="nowrap"><?php echo $queryData['connection'] ?> </td>
22
  <td class="nowrap"><?php echo sprintf('%0.2f', $queryData['time'] * 1000) ?> ms</td>
28
 
29
  </div>
30
  <div>
31
+ <?php echo $contextHelper->render($prefix . '-' . $index, $queryData['context']); ?>
32
  </div>
33
 
34
  <div class="text-small font-normal">
54
  </div>
55
 
56
  <?php if (isset($queryData['trace'])): ?>
57
+ <?php echo $rendererHelper->renderCallStack($prefix . $index, $queryData['trace']) ?>
58
  <?php endif; ?>
59
  </td>
60
  </tr>
app/design/frontend/base/default/template/ecocode_profiler/collector/request/panel.phtml CHANGED
@@ -3,6 +3,9 @@
3
 
4
  /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $collector */
5
  $collector = $this->getCollector();
 
 
 
6
  ?>
7
 
8
 
@@ -18,7 +21,7 @@ $collector = $this->getCollector();
18
  <p>No GET parameters</p>
19
  </div>
20
  <?php else: ?>
21
- <?php echo $this->renderBag($collector->getRequestQuery()) ?>
22
  <?php endif ?>
23
 
24
  <h3>POST Parameters</h3>
@@ -28,7 +31,7 @@ $collector = $this->getCollector();
28
  <p>No POST parameters</p>
29
  </div>
30
  <?php else: ?>
31
- <?php echo $this->renderBag($collector->getRequestRequest()) ?>
32
  <?php endif ?>
33
 
34
  <h3>Request Attributes</h3>
@@ -38,7 +41,7 @@ $collector = $this->getCollector();
38
  <p>No attributes</p>
39
  </div>
40
  <?php else: ?>
41
- <?php echo $this->renderBag($collector->getRequestAttributes()) ?>
42
  <?php endif ?>
43
 
44
  <h3>Cookies</h3>
@@ -48,11 +51,11 @@ $collector = $this->getCollector();
48
  <p>No cookies</p>
49
  </div>
50
  <?php else: ?>
51
- <?php echo $this->renderBag($collector->getRequestCookies()) ?>
52
  <?php endif ?>
53
 
54
  <h3>Request Headers</h3>
55
- <?php echo $this->renderBag($collector->getRequestHeaders()) ?>
56
 
57
  <h3>Request Content</h3>
58
 
@@ -71,7 +74,7 @@ $collector = $this->getCollector();
71
  <?php endif ?>
72
 
73
  <h3>Server Parameters</h3>
74
- <?php echo $this->renderBag($collector->getRequestServer()) ?>
75
  </div>
76
  </div>
77
 
@@ -81,83 +84,121 @@ $collector = $this->getCollector();
81
  <div class="tab-content">
82
  <h3>Response Headers</h3>
83
 
84
- <?php echo $this->renderBag($collector->getResponseHeaders()) ?>
85
  </div>
86
  </div>
87
 
88
- <!--<div class="tab {{ collector.sessionmetadata is empty ? 'disabled' }}">
 
 
 
89
  <h3 class="tab-title">Session</h3>
90
 
91
  <div class="tab-content">
92
  <h3>Session Metadata</h3>
93
 
94
- {% if collector.sessionmetadata is empty %}
95
- <div class="empty">
96
- <p>No session metadata</p>
97
- </div>
98
- {% else %}
99
- {{ include('@WebProfiler/Profiler/table.html.twig', { data: collector.sessionmetadata }, with_context = false) }}
100
- {% endif %}
101
 
102
- <h3>Session Attributes</h3>
103
 
104
- {% if collector.sessionattributes is empty %}
105
- <div class="empty">
106
- <p>No session attributes</p>
107
- </div>
108
- {% else %}
109
- {{ include('@WebProfiler/Profiler/table.html.twig', { data: collector.sessionattributes, labels: ['Attribute', 'Value'] }, with_context = false) }}
110
- {% endif %}
111
- </div>
112
- </div>
113
 
114
- <div class="tab {{ collector.flashes is empty ? 'disabled' }}">
115
- <h3 class="tab-title">Flashes</h3>
116
 
117
- <div class="tab-content">
118
- <h3>Flashes</h3>
 
 
 
 
 
 
 
 
119
 
120
- {% if collector.flashes is empty %}
121
- <div class="empty">
122
- <p>No flash messages were created.</p>
123
- </div>
124
- {% else %}
125
- {{ include('@WebProfiler/Profiler/table.html.twig', { data: collector.flashes }, with_context = false) }}
126
- {% endif %}
127
  </div>
128
  </div>
129
 
130
- {% if profile.parent %}
131
- <div class="tab">
132
- <h3 class="tab-title">Parent Request</h3>
133
 
134
  <div class="tab-content">
135
- <h3>
136
- <a href="{{ path('_profiler', { token: profile.parent.token }) }}">Return to parent request</a>
137
- <small>(token = {{ profile.parent.token }})</small>
138
- </h3>
139
 
140
- {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: profile.parent.getcollector('request').requestattributes }, with_context = false) }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  </div>
142
  </div>
143
- {% endif %}
144
-
145
- {% if profile.children|length %}
146
- <div class="tab">
147
- <h3 class="tab-title">Sub Requests <span class="badge">{{ profile.children|length }}</span></h3>
148
-
149
- <div class="tab-content">
150
- {% for child in profile.children %}
151
- <h3>
152
- <a href="{{ path('_profiler', { token: child.token }) }}">
153
- {{- child.getcollector('request').requestattributes.get('_controller') -}}
154
- </a>
155
- <small>(token = {{ child.token }})</small>
156
- </h3>
157
-
158
- {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: child.getcollector('request').requestattributes }, with_context = false) }}
159
- {% endfor %}
160
  </div>
161
- </div>
162
- {% endif %}-->
163
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $collector */
5
  $collector = $this->getCollector();
6
+
7
+ /** @var Ecocode_Profiler_Helper_Renderer $renderHelper */
8
+ $renderHelper = Mage::helper('ecocode_profiler/renderer');
9
  ?>
10
 
11
 
21
  <p>No GET parameters</p>
22
  </div>
23
  <?php else: ?>
24
+ <?php echo $renderHelper->renderBag($collector->getRequestQuery()) ?>
25
  <?php endif ?>
26
 
27
  <h3>POST Parameters</h3>
31
  <p>No POST parameters</p>
32
  </div>
33
  <?php else: ?>
34
+ <?php echo $renderHelper->renderBag($collector->getRequestRequest()) ?>
35
  <?php endif ?>
36
 
37
  <h3>Request Attributes</h3>
41
  <p>No attributes</p>
42
  </div>
43
  <?php else: ?>
44
+ <?php echo $renderHelper->renderBag($collector->getRequestAttributes()) ?>
45
  <?php endif ?>
46
 
47
  <h3>Cookies</h3>
51
  <p>No cookies</p>
52
  </div>
53
  <?php else: ?>
54
+ <?php echo $renderHelper->renderBag($collector->getRequestCookies()) ?>
55
  <?php endif ?>
56
 
57
  <h3>Request Headers</h3>
58
+ <?php echo $renderHelper->renderBag($collector->getRequestHeaders()) ?>
59
 
60
  <h3>Request Content</h3>
61
 
74
  <?php endif ?>
75
 
76
  <h3>Server Parameters</h3>
77
+ <?php echo $renderHelper->renderBag($collector->getRequestServer()) ?>
78
  </div>
79
  </div>
80
 
84
  <div class="tab-content">
85
  <h3>Response Headers</h3>
86
 
87
+ <?php echo $renderHelper->renderBag($collector->getResponseHeaders()) ?>
88
  </div>
89
  </div>
90
 
91
+ <?php $sessionMetadata = $collector->getSessionMetadata() ?>
92
+ <?php $sessionAttributes = $collector->getSessionAttributes() ?>
93
+
94
+ <div class="tab <?php echo !($sessionMetadata && $sessionAttributes) ? '' : 'disabled' ?>">
95
  <h3 class="tab-title">Session</h3>
96
 
97
  <div class="tab-content">
98
  <h3>Session Metadata</h3>
99
 
100
+ <?php if (empty($sessionMetadata)): ?>
101
+ <div class="empty">
102
+ <p>No session metadata</p>
103
+ </div>
104
+ <?php else: ?>
105
+ <?php echo $renderHelper->renderTable($sessionMetadata); ?>
106
+ <?php endif ?>
107
 
108
+ <h3>Sessions</h3>
109
 
110
+ <?php if (empty($sessionAttributes)): ?>
111
+ <div class="empty">
112
+ <p>No session attributes</p>
113
+ </div>
114
+ <?php else: ?>
115
+ <?php foreach ($sessionAttributes['namespace'] as $namespace => $data): ?>
116
+ <h4><?php echo uc_words($namespace) ?></h4>
117
+ <?php echo $renderHelper->renderTable($data); ?>
118
+ <?php endforeach; ?>
119
 
 
 
120
 
121
+ <?php foreach ($sessionAttributes['store'] as $namespace => $data): ?>
122
+ <h4><?php echo uc_words($namespace) ?></h4>
123
+ <?php echo $renderHelper->renderTable($data); ?>
124
+ <?php endforeach; ?>
125
+
126
+ <?php foreach ($sessionAttributes['global'] as $namespace => $data): ?>
127
+ <h4><?php echo uc_words($namespace) ?></h4>
128
+ <?php echo $renderHelper->renderTable($data); ?>
129
+ <?php endforeach; ?>
130
+ <?php endif ?>
131
 
 
 
 
 
 
 
 
132
  </div>
133
  </div>
134
 
135
+ <div class="tab <?php echo $collector->getMessages() ? '' : 'disabled' ?>">
136
+ <h3 class="tab-title">Messages <span class="badge"><?php echo count($collector->getMessages()) ?></span></h3>
 
137
 
138
  <div class="tab-content">
139
+ <h3>Messages</h3>
 
 
 
140
 
141
+ <?php if (empty($collector->getMessages())): ?>
142
+ <div class="empty">
143
+ <p>No messages were created.</p>
144
+ </div>
145
+ <?php else: ?>
146
+ <table>
147
+ <thead>
148
+ <tr>
149
+ <th scope="col">Session</th>
150
+ <th scope="col">Namespace</th>
151
+ <th scope="col">Type</th>
152
+ <th class="nowrap">Message</th>
153
+ </tr>
154
+ </thead>
155
+ <tbody>
156
+ <?php foreach ($collector->getMessages() as $message): ?>
157
+ <tr>
158
+ <td class="nowrap" scope="row"><?php echo $message['class_group'] ?></td>
159
+ <td class="nowrap"><?php echo $message['namespace'] ?></td>
160
+ <td class="nowrap"><?php echo $message['type'] ?></td>
161
+ <td><?php echo $message['text'] ?></td>
162
+ </tr>
163
+ <?php endforeach; ?>
164
+ </tbody>
165
+ </table>
166
+
167
+ <?php endif; ?>
168
  </div>
169
  </div>
170
+ <!--
171
+ {% if profile.parent %}
172
+ <div class="tab">
173
+ <h3 class="tab-title">Parent Request</h3>
174
+
175
+ <div class="tab-content">
176
+ <h3>
177
+ <a href="{{ path('_profiler', { token: profile.parent.token }) }}">Return to parent request</a>
178
+ <small>(token = {{ profile.parent.token }})</small>
179
+ </h3>
180
+
181
+ {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: profile.parent.getcollector('request').requestattributes }, with_context = false) }}
182
+ </div>
 
 
 
 
183
  </div>
184
+ {% endif %}
185
+
186
+ {% if profile.children|length %}
187
+ <div class="tab">
188
+ <h3 class="tab-title">Sub Requests <span class="badge">{{ profile.children|length }}</span></h3>
189
+
190
+ <div class="tab-content">
191
+ {% for child in profile.children %}
192
+ <h3>
193
+ <a href="{{ path('_profiler', { token: child.token }) }}">
194
+ {{- child.getcollector('request').requestattributes.get('_controller') -}}
195
+ </a>
196
+ <small>(token = {{ child.token }})</small>
197
+ </h3>
198
+
199
+ {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: child.getcollector('request').requestattributes }, with_context = false) }}
200
+ {% endfor %}
201
+ </div>
202
+ </div>
203
+ {% endif %}-->
204
+ </div>
app/design/frontend/base/default/template/ecocode_profiler/collector/request/toolbar.phtml CHANGED
@@ -1,20 +1,40 @@
1
  <?php
2
- /** @var Ecocode_Profiler_Block_Collector_Base $this */
3
 
4
  /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $collector */
5
- $collector = $this->getCollector();
6
- $token = $this->getToken();
7
- $requestStatusCodeColor = $collector->getStatusCode() >= 400 ? 'red' : $collector->getStatusCode() >= 300 ? 'yellow' : 'green';
 
 
 
8
  ?>
9
 
10
- <div class="sf-toolbar-block sf-toolbar-block-<?php echo $collector->getName()?> sf-toolbar-status-normal ">
11
- <a target="_blank" href="<?php echo Mage::helper('ecocode_profiler')->getCollectorUrl($token, $collector); ?>">
12
  <div class="sf-toolbar-icon">
13
- <span class="sf-toolbar-status sf-toolbar-status-<?php echo $requestStatusCodeColor?>"><?php echo $collector->getStatusCode()?></span>
14
- <?php if($collector->getRoute()): ?>
15
- <span class="sf-toolbar-label"><?php echo $collector->getMethod() !== 'GET' ? $collector->getMethod() : ''?> @</span>
16
- <span class="sf-toolbar-value sf-toolbar-info-piece-additional"><?php echo $collector->getRoute()?></span>
17
- <?php endif?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  </div>
19
  </a>
20
  <div class="sf-toolbar-info">
@@ -26,7 +46,7 @@ $requestStatusCodeColor = $collector->getStatusCode() >= 400 ? 'red' : $collecto
26
 
27
 
28
  <div class="sf-toolbar-info-piece">
29
- <b>Route Name</b><span><?php echo $collector->getRoute() ?></span>
30
  </div>
31
  <div class="sf-toolbar-info-piece">
32
  <b>Module</b><span><?php echo $collector->getModuleName() ?></span>
@@ -39,7 +59,7 @@ $requestStatusCodeColor = $collector->getStatusCode() >= 400 ? 'red' : $collecto
39
  <?php $controllerData = $collector->getController(); ?>
40
  <div class="sf-toolbar-info-piece">
41
  <b>Controller class</b>
42
- <span><?php echo $controllerData['class'] ?></span>
43
  </div>
44
  <div class="sf-toolbar-info-piece">
45
  <b>Full action name</b>
@@ -47,5 +67,21 @@ $requestStatusCodeColor = $collector->getStatusCode() >= 400 ? 'red' : $collecto
47
  </div>
48
  </div>
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  </div>
51
- </div>
1
  <?php
2
+ /** @var Ecocode_Profiler_Block_Collector_Request_Toolbar $this */
3
 
4
  /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $collector */
5
+ $collector = $this->getCollector();
6
+ $token = $this->getToken();
7
+ $requestStatusCodeColor = $collector->getStatusCode() >= 400 ? 'red' : $collector->getStatusCode() >= 300 ? 'yellow' : 'green';
8
+
9
+ /** @var Ecocode_Profiler_Helper_Data $helper */
10
+ $helper = Mage::helper('ecocode_profiler');
11
  ?>
12
 
13
+ <div class="sf-toolbar-block sf-toolbar-block-<?php echo $collector->getName() ?> sf-toolbar-status-normal ">
14
+ <a target="_blank" href="<?php echo $helper->getCollectorUrl($token, $collector); ?>">
15
  <div class="sf-toolbar-icon">
16
+ <span
17
+ class="sf-toolbar-status sf-toolbar-status-<?php echo $requestStatusCodeColor ?>"><?php echo $collector->getStatusCode() ?></span>
18
+ <?php if ($collector->getRoute()): ?>
19
+ <?php if ($collector->getRedirect()): ?>
20
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
21
+ <path style="fill:#aaa" d="M23.06,7.83L14,0.38a1.25,1.25,0,0,0-2,.89V4.09a13.61,13.61,0,0,1-2.2.61l-1.3.47C8,
22
+ 5.35,7.59,5.6,7.12,5.81l-0.69.35-0.72.45a10.62,10.62,0,0,0-1.41,1A13.22,13.22,0,0,0,3,8.82a15.31,15.31,
23
+ 0,0,0-1.13,1.46A17.63,17.63,0,0,0,1,11.93c-0.18.58-.34,1.16-0.48,1.71S0.45,14.76.43,15.29a10.2,10.2,0,0,0,.16,
24
+ 1.5,5.72,5.72,0,0,0,.33,1.34c0.14,0.41.26,0.82,0.42,1.19,0.37,0.71.67,1.38,1,1.94l1,1.46c0.32,0.41.63,0.75,0.87,
25
+ 1s0.51,0.09.43-.22-0.23-.75-0.35-1.23L4,20.69c-0.1-.58-0.09-1.22-0.14-1.86,0-.32.05-0.65,0.08-1a3.44,3.44,0,0,1,
26
+ .16-1A6.44,6.44,0,0,1,4.41,16l0.41-.8c0.2-.22.38-0.44,0.55-0.65L6,14c0.23-.14.5-0.24,0.72-0.37a7.52,7.52,0,0,1,
27
+ .79-0.25,4.48,4.48,0,0,1,.84-0.15l0.41-.06H9.22c0.3,0,.56,0,0.85,0l0.72,0.07a3.77,3.77,0,0,1,1.2.21v3.17a1.25,
28
+ 1.25,0,0,0,2,.89l9-7.45A1.46,1.46,0,0,0,23.06,7.83Z"/>
29
+ </svg>
30
+
31
+ <?php endif; ?>
32
+ <span
33
+ class="sf-toolbar-label"><?php echo $collector->getMethod() !== 'GET' ? $collector->getMethod() : '' ?>
34
+ @</span>
35
+ <span
36
+ class="sf-toolbar-value sf-toolbar-info-piece-additional"><?php echo $collector->getRoute() ?></span>
37
+ <?php endif ?>
38
  </div>
39
  </a>
40
  <div class="sf-toolbar-info">
46
 
47
 
48
  <div class="sf-toolbar-info-piece">
49
+ <b>Route Name</b><span>@<?php echo $collector->getRoute() ?></span>
50
  </div>
51
  <div class="sf-toolbar-info-piece">
52
  <b>Module</b><span><?php echo $collector->getModuleName() ?></span>
59
  <?php $controllerData = $collector->getController(); ?>
60
  <div class="sf-toolbar-info-piece">
61
  <b>Controller class</b>
62
+ <span><?php echo $this->renderHandler($collector->getController()); ?></span>
63
  </div>
64
  <div class="sf-toolbar-info-piece">
65
  <b>Full action name</b>
67
  </div>
68
  </div>
69
 
70
+ <?php if ($redirect = $collector->getRedirect()): ?>
71
+ <div class="sf-toolbar-info-group">
72
+ <div class="sf-toolbar-info-piece">
73
+ <b>
74
+ <span class="sf-toolbar-redirection-status sf-toolbar-status-yellow">
75
+ <?php echo $redirect['status_code'] ?>
76
+ </span>
77
+ Redirect from
78
+ </b>
79
+ <span>
80
+ <?php echo $this->renderHandler($redirect['controller'], $redirect['route'], $redirect['method'] !== 'GET'); ?>
81
+ (<a target="_blank" href="<?php echo $helper->getUrl($redirect['token']) ?>"><?php echo $redirect['token'] ?></a>)
82
+ </span>
83
+ </div>
84
+ </div>
85
+ <?php endif ?>
86
  </div>
87
+ </div>
app/design/frontend/base/default/template/ecocode_profiler/collector/request/toolbar/handler.phtml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /** @var Ecocode_Profiler_Block_Renderer_Request_ToolbarHandler $this */
3
+
4
+ /** @var Ecocode_Profiler_Helper_Code $codeHelper */
5
+ $codeHelper = Mage::helper('ecocode_profiler/code');
6
+
7
+ $controller = $this->getController();
8
+ ?>
9
+
10
+ <?php if (isset($controller['class'])): ?>
11
+ <?php if ($this->getMethod()): ?>
12
+ <span class="sf-toolbar-status sf-toolbar-redirection-method"><?php echo $this->getMethod() ?></span>
13
+ <?php endif; ?>
14
+ <?php $link = $codeHelper->getFileLink($controller['file'], $controller['line']); ?>
15
+ <?php if ($link): ?>
16
+ <a target="profiler_link_target" href="<?php echo $link ?>" title="<?php echo $controller['file'] ?>">
17
+ <?php endif; ?>
18
+
19
+ <?php if ($this->getRoute()): ?>
20
+ @<?php echo $this->getRoute(); ?>
21
+ <?php else: ?>
22
+ <?php echo strip_tags($codeHelper->abbrClass($controller['class'])); ?>
23
+ <?php echo $controller['method'] ? '::' . $controller['method'] : ''; ?>
24
+ <?php endif; ?>
25
+
26
+ <?php if ($link): ?>
27
+ </a>
28
+ <?php endif; ?>
29
+
30
+ <?php else: ?>
31
+ <span><?php echo $this->getRoute() ? $this->getRoute() : $controller?></span>
32
+ <?php endif; ?>
app/design/frontend/base/default/template/ecocode_profiler/collector/translation/panel/table.phtml CHANGED
@@ -1,7 +1,13 @@
1
  <?php
2
  /** @var Ecocode_Profiler_Helper_ValueExporter $valueExporter */
3
  $valueExporter = $this->helper('ecocode_profiler/valueExporter');
4
- $prefix = 'trans-' . uniqid(); ?>
 
 
 
 
 
 
5
  <table>
6
  <thead>
7
  <tr>
@@ -16,7 +22,7 @@ $prefix = 'trans-' . uniqid(); ?>
16
  <?php foreach ($this->getData('messages') as $index => $message): ?>
17
  <tr>
18
  <td class="font-normal text-small"><?php echo $message['locale'] ?></td>
19
- <td class="font-normal text-small text-bold"><?php echo $message['module'] ?></td>
20
  <td class="font-normal text-small"><?php echo $message['count'] ?></td>
21
  <td>
22
  <?php echo $message['code'] ?>
@@ -47,25 +53,15 @@ $prefix = 'trans-' . uniqid(); ?>
47
  <tr class="hidden" id="traces-<?php echo $prefix . $index ?>">
48
  <td colspan="3"></td>
49
  <td colspan="2">
50
- <div id="stack-<?php echo $prefix . $index ?>" class="hiddenx">
51
  <table class="">
52
  <tbody>
53
- <?php foreach ($message['traces'] as $j => $trace): ?>
54
  <tr>
55
  <td class="nowrap">#<?php echo $j + 1 ?></td>
 
56
  <td>
57
- <ul class="sf-call-stack ">
58
- <?php foreach ($trace as $item): ?>
59
- <li>
60
- <?php echo isset($item['class']) ? $item['class'] . '::' : '' ?><?php echo $item['function'] ?>
61
- <br>
62
- <?php if (isset($item['file'])): ?>
63
- <small><?php echo $item['file'] ?>
64
- ::<?php echo $item['line'] ?></small>
65
- <?php endif; ?>
66
- </li>
67
- <?php endforeach; ?>
68
- </ul>
69
  </td>
70
  </tr>
71
  <?php endforeach; ?>
@@ -79,4 +75,4 @@ $prefix = 'trans-' . uniqid(); ?>
79
 
80
  <?php endforeach; ?>
81
  </tbody>
82
- </table>
1
  <?php
2
  /** @var Ecocode_Profiler_Helper_ValueExporter $valueExporter */
3
  $valueExporter = $this->helper('ecocode_profiler/valueExporter');
4
+ $prefix = 'trans-' . uniqid();
5
+
6
+ /** @var Ecocode_Profiler_Helper_Renderer $rendererHelper */
7
+ $rendererHelper = Mage::helper('ecocode_profiler/renderer');
8
+ ?>
9
+
10
+
11
  <table>
12
  <thead>
13
  <tr>
22
  <?php foreach ($this->getData('messages') as $index => $message): ?>
23
  <tr>
24
  <td class="font-normal text-small"><?php echo $message['locale'] ?></td>
25
+ <td class="font-normal text-small text-bold nowrap"><?php echo $message['module'] ?></td>
26
  <td class="font-normal text-small"><?php echo $message['count'] ?></td>
27
  <td>
28
  <?php echo $message['code'] ?>
53
  <tr class="hidden" id="traces-<?php echo $prefix . $index ?>">
54
  <td colspan="3"></td>
55
  <td colspan="2">
56
+ <div id="stack-<?php echo $prefix . $index ?>">
57
  <table class="">
58
  <tbody>
59
+ <?php foreach (array_values($message['traces']) as $j => $trace): ?>
60
  <tr>
61
  <td class="nowrap">#<?php echo $j + 1 ?></td>
62
+ <td class="nowrap"><?php echo $trace['count']?>x</td>
63
  <td>
64
+ <?php echo $rendererHelper->renderCallStack($j + 1, $trace['trace'], false) ?>
 
 
 
 
 
 
 
 
 
 
 
65
  </td>
66
  </tr>
67
  <?php endforeach; ?>
75
 
76
  <?php endforeach; ?>
77
  </tbody>
78
+ </table>
app/design/frontend/base/default/template/ecocode_profiler/layout.phtml CHANGED
@@ -82,6 +82,6 @@ FZkHkO+YN19jJj7/cVXHqlaP9oN2fwF3BYdp8BgRAQAAAABJRU5ErkJggg==">
82
  </div>
83
  </div>
84
 
85
-
86
  </body>
87
  </html>
82
  </div>
83
  </div>
84
 
85
+ <iframe name="profiler_link_target" class="hidden"></iframe>
86
  </body>
87
  </html>
app/design/frontend/base/default/template/ecocode_profiler/profiler/base.css.phtml CHANGED
@@ -932,4 +932,4 @@ table.logs .sf-call-stack abbr {
932
  .btn-sm svg {
933
  margin-left: 2px;
934
  }
935
- }
932
  .btn-sm svg {
933
  margin-left: 2px;
934
  }
935
+ }
app/design/frontend/base/default/template/ecocode_profiler/profiler/summery.phtml CHANGED
@@ -1,90 +1,114 @@
1
  <?php
2
  /** @var Ecocode_Profiler_Model_Profile $profile */
3
  $profile = Mage::registry('current_profile');
 
 
 
 
 
 
4
  ?>
5
  <?php if ($profile): ?>
6
  <?php
7
- /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $requestCollector */
8
- $requestCollector = $profile->getCollector('request');
9
- $statusCode = $requestCollector->getStatusCode();
10
- $cssClass = ($statusCode > 399) ? 'status-error' : $statusCode > 299 ? 'status-warning' : 'status-success';
11
  ?>
12
 
13
- <div class="status <?php echo $cssClass?>">
14
- <div class="container">
15
- <h2 class="break-long-words">
16
- <?php if (in_array(strtoupper($profile->getMethod()), ['GET', 'HEAD'])): ?>
17
- <a href="<?php echo $profile->getUrl()?>"><?php echo $profile->getUrl()?></a>
18
- <?php else: ?>
19
- <?php echo $profile->getUrl()?>
20
- <?php endif;?>
21
- </h2>
22
-
23
- <!-- {% if request_collector is defined and request_collector.redirect -%}
24
- {%- set redirect = request_collector.redirect -%}
25
- {%- set controller = redirect.controller -%}
26
- {%- set redirect_route = '@' ~ redirect.route %}
27
- <dl class="metadata">
28
- <dt>
29
- <span class="label">{{ redirect.status_code }}</span>
30
- Redirect from
31
- </dt>
32
- <dd>
33
- {{ 'GET' != redirect.method ? redirect.method }}
34
- {% if redirect.controller.class is defined -%}
35
- {%- set link = controller.file|file_link(controller.line) -%}
36
- {% if link %}<a href="{{ link }}" title="{{ controller.file }}">{% endif -%}
37
- {{ redirect_route }}
38
- {%- if link %}</a>{% endif -%}
39
- {%- else -%}
40
- {{ redirect_route }}
41
- {%- endif %}
42
- (<a href="{{ path('_profiler', { token: redirect.token }) }}">{{ redirect.token }}</a>)
43
- </dd>
44
- </dl>
45
- {%- endif %}-->
46
-
47
- <!-- {% if request_collector and request_collector.forward|default(false) and request_collector.forward.controller.class is defined -%}
48
- {%- set forward = request_collector.forward -%}
49
- {%- set controller = forward.controller -%}
50
- <dl class="metadata">
51
- <dt>Forwarded to</dt>
52
- <dd>
53
- {% set link = controller.file|file_link(controller.line) -%}
54
- {%- if link %}<a href="{{ link }}" title="{{ controller.file }}">{% endif -%}
55
- {{- controller.class|abbr_class|striptags -}}
56
- {{- controller.method ? ' :: ' ~ controller.method }}
57
- {%- if link %}</a>{% endif %}
58
- (<a href="{{ path('_profiler', { token: forward.token }) }}">{{ forward.token }}</a>)
59
- </dd>
60
- </dl>
61
- {%- endif %}-->
62
-
63
- <dl class="metadata">
64
- <dt>Method</dt>
65
- <dd><?php echo strtoupper($profile->getMethod()) ?></dd>
66
 
67
- <?php if ($profile->hasCollector('request')):?>
68
  <?php
69
- /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $collector */
70
- $collector = $profile->getCollector('request');
71
  ?>
72
- <dt>Route</dt>
73
- <dd><?php echo $collector->getRoute(); ?></dd>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  <?php endif; ?>
75
 
76
- <dt>HTTP Status</dt>
77
- <dd><?php echo $statusCode ?></dd>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- <dt>IP</dt>
80
- <dd><?php echo $profile->getIp() ?></dd>
 
 
 
 
 
 
 
 
 
81
 
82
- <dt>Profiled on</dt>
83
- <dd><?php echo date('r', $profile->getTime()) ?></dd>
84
 
85
- <dt>Token</dt>
86
- <dd><?php echo $profile->getToken(); ?></dd>
87
- </dl>
 
 
 
 
 
 
 
88
  </div>
89
- </div>
90
- <?php endif;?>
1
  <?php
2
  /** @var Ecocode_Profiler_Model_Profile $profile */
3
  $profile = Mage::registry('current_profile');
4
+
5
+ /** @var Ecocode_Profiler_Helper_Data $helper */
6
+ $helper = Mage::helper('ecocode_profiler');
7
+
8
+ /** @var Ecocode_Profiler_Helper_Code $codeHelper */
9
+ $codeHelper = Mage::helper('ecocode_profiler/code');
10
  ?>
11
  <?php if ($profile): ?>
12
  <?php
13
+ /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $requestCollector */
14
+ $requestCollector = $profile->getCollector('request');
15
+ $statusCode = $requestCollector->getStatusCode();
16
+ $cssClass = ($statusCode > 399) ? 'status-error' : $statusCode > 299 ? 'status-warning' : 'status-success';
17
  ?>
18
 
19
+ <div class="status <?php echo $cssClass ?>">
20
+ <div class="container">
21
+ <h2 class="break-long-words">
22
+ <?php if (in_array(strtoupper($profile->getMethod()), ['GET', 'HEAD'])): ?>
23
+ <a href="<?php echo $profile->getUrl() ?>"><?php echo $profile->getUrl() ?></a>
24
+ <?php else: ?>
25
+ <?php echo $profile->getUrl() ?>
26
+ <?php endif; ?>
27
+ </h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
+ <?php if ($redirect = $requestCollector->getRedirect()): ?>
30
  <?php
31
+ $controller = $redirect['controller'];
32
+ $redirectRoute = '@' . $redirect['route'];
33
  ?>
34
+ <dl class="metadata">
35
+ <dt>
36
+ <span class="label"><?php echo $redirect['status_code'] ?></span>
37
+ Redirect from
38
+ </dt>
39
+ <dd>
40
+ <?php echo $redirect['method'] == 'GET' ? '' : $redirect['method'] ?>
41
+ <?php if ($controller = $redirect['controller']): ?>
42
+ <?php $link = $codeHelper->getFileLink($controller['file'], $controller['line']); ?>
43
+
44
+ <?php if ($link): ?>
45
+ <a target="profiler_link_target" href="<?php echo $link ?>"
46
+ title="<?php echo $controller['file'] ?>">
47
+ <?php echo $redirectRoute; ?>
48
+ </a>
49
+ <?php else: ?>
50
+ <?php echo $redirectRoute; ?>
51
+ <?php endif; ?>
52
+ <?php endif; ?>
53
+ (<a href="<?php echo $helper->getUrl($redirect['token']) ?>"><?php echo $redirect['token']; ?></a>)
54
+ </dd>
55
+ </dl>
56
  <?php endif; ?>
57
 
58
+ <!-- {% if request_collector and request_collector.forward|default(false) and request_collector.forward.controller.class is defined -%}
59
+ {%- set forward = request_collector.forward -%}
60
+ {%- set controller = forward.controller -%}
61
+ <dl class="metadata">
62
+ <dt>Forwarded to</dt>
63
+ <dd>
64
+ {% set link = controller.file|file_link(controller.line) -%}
65
+ {%- if link %}<a href="{{ link }}" title="{{ controller.file }}">{% endif -%}
66
+ {{- controller.class|abbr_class|striptags -}}
67
+ {{- controller.method ? ' :: ' ~ controller.method }}
68
+ {%- if link %}</a>{% endif %}
69
+ (<a href="{{ path('_profiler', { token: forward.token }) }}">{{ forward.token }}</a>)
70
+ </dd>
71
+ </dl>
72
+ {%- endif %}-->
73
+
74
+ <dl class="metadata">
75
+ <dt>Method</dt>
76
+ <dd><?php echo strtoupper($profile->getMethod()) ?></dd>
77
+
78
+ <?php if ($profile->hasCollector('request')): ?>
79
+ <?php
80
+ /** @var Ecocode_Profiler_Model_Collector_RequestDataCollector $collector */
81
+ $collector = $profile->getCollector('request');
82
+ ?>
83
+ <dt>Route</dt>
84
+ <dd>
85
+ <?php if ($controller = $collector->getController()): ?>
86
+ <?php $link = $codeHelper->getFileLink($controller['file'], $controller['line']); ?>
87
 
88
+ <?php if ($link): ?>
89
+ <a target="profiler_link_target" href="<?php echo $link ?>"
90
+ title="<?php echo $controller['file'] ?>">
91
+ @<?php echo $collector->getRoute(); ?>
92
+ </a>
93
+ <?php else: ?>
94
+ @<?php echo $collector->getRoute(); ?>
95
+ <?php endif; ?>
96
+ <?php endif; ?>
97
+ </dd>
98
+ <?php endif; ?>
99
 
100
+ <dt>HTTP Status</dt>
101
+ <dd><?php echo $statusCode ?></dd>
102
 
103
+ <dt>IP</dt>
104
+ <dd><?php echo $profile->getIp() ?></dd>
105
+
106
+ <dt>Profiled on</dt>
107
+ <dd><?php echo date('r', $profile->getTime()) ?></dd>
108
+
109
+ <dt>Token</dt>
110
+ <dd><?php echo $profile->getToken(); ?></dd>
111
+ </dl>
112
+ </div>
113
  </div>
114
+ <?php endif; ?>
 
app/design/frontend/base/default/template/ecocode_profiler/renderer/bag.phtml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /** @var Ecocode_Profiler_Block_Renderer_Bag $this */
3
+
4
+ /** @var Ecocode_Profiler_Helper_ValueExporter $valueExport */
5
+ $valueExport = $this->helper('ecocode_profiler/valueExporter');
6
+
7
+ $bag = $this->getBag();
8
+ ?>
9
+
10
+ <table class="<?php echo $this->getData('class') ?>">
11
+ <thead>
12
+ <?php $labels = $this->getLabels(); ?>
13
+ <tr>
14
+ <th scope="col" class="key"><?php echo isset($labels[0]) ? $labels[0] : 'Key' ?></th>
15
+ <th scope="col"><?php echo isset($labels[1]) ? $labels[1] : 'Value' ?></th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <?php if ($bag = $this->getBag()): ?>
20
+
21
+ <?php foreach ($bag->keys() as $key): ?>
22
+ <tr>
23
+ <th><?php echo $key ?></th>
24
+ <td><?php echo $valueExport->exportValue($bag->get($key)) ?></td>
25
+ </tr>
26
+
27
+ <?php endforeach; ?>
28
+ <?php else: ?>
29
+ <tr>
30
+ <td colspan="2">(no data)</td>
31
+ </tr>
32
+ <?php endif; ?>
33
+ </tbody>
34
+ </table>
app/design/frontend/base/default/template/ecocode_profiler/renderer/call-stack.phtml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /** @var Ecocode_Profiler_Block_Renderer_CallStack $this */
3
+
4
+ /** @var Ecocode_Profiler_Helper_Code $codeHelper */
5
+ $codeHelper = Mage::helper('ecocode_profiler/code');
6
+
7
+
8
+ $trace = $this->getStack();
9
+ ?>
10
+ <?php if ($trace): ?>
11
+ <?php if ($this->shouldWarp()): ?>
12
+ <div id="stack-<?php echo $this->getStackId() ?>" class="hidden">
13
+ <strong class="font-normal text-small">Trace:</strong>
14
+ <?php endif ?>
15
+ <ul class="sf-call-stack ">
16
+ <?php foreach ($trace as $call): ?>
17
+ <?php
18
+ $from = '-';
19
+ if (isset($call['class'])) {
20
+ $from = $codeHelper->abbrClass($call['class']) . '::' . $codeHelper->abbrMethod($call['function']);
21
+ } elseif (isset($call['function'])) {
22
+ $from = $codeHelper->abbrMethod($call['function']);
23
+ } elseif (isset($call['file'])) {
24
+ $from = $call['file'];
25
+ }
26
+
27
+ $fileName = null;
28
+ if (isset($call['file'], $call['line'])) {
29
+ $fileName = str_replace('\\', '/', $call['file']);
30
+ $fileName = explode('/', $fileName);
31
+ $fileName = end($fileName);
32
+ }
33
+ ?>
34
+
35
+ <li>
36
+ <?php echo $from; ?>
37
+ <?php if ($fileName): ?>
38
+ <span class="text-small">
39
+ (called from <?php echo $codeHelper->formatFile($call['file'], $call['line'], $fileName) ?>)
40
+ </span>
41
+ <?php endif; ?>
42
+ </li>
43
+ <?php endforeach; ?>
44
+ </ul>
45
+
46
+ <?php if ($this->shouldWarp()): ?>
47
+ </div>
48
+ <?php endif ?>
49
+ <?php endif; ?>
app/design/frontend/base/default/template/ecocode_profiler/renderer/context.phtml CHANGED
@@ -6,7 +6,11 @@ $prefix = $this->getData('prefix');
6
  $context = $this->getData('context');
7
 
8
  /** @var Ecocode_Profiler_Helper_ValueExporter $exporter */
9
- $exporter = Mage::helper('ecocode_profiler/valueExporter')
 
 
 
 
10
  ?>
11
 
12
  <div class="context font-normal text-small">
@@ -17,6 +21,7 @@ $exporter = Mage::helper('ecocode_profiler/valueExporter')
17
  data-toggle-alt-content="Hide metadata">View metadata</a>
18
  <div id="context-<?php echo $prefix . $context->getId() ?>" class="hidden text-small">
19
  <table>
 
20
  <?php foreach($context->getData() as $key => $value):?>
21
  <tr>
22
  <th class="key"><?php echo $key?></th>
6
  $context = $this->getData('context');
7
 
8
  /** @var Ecocode_Profiler_Helper_ValueExporter $exporter */
9
+ $exporter = Mage::helper('ecocode_profiler/valueExporter');
10
+
11
+ $codeHelper = Mage::helper('ecocode_profiler/code');
12
+
13
+ $data = $context->getData();
14
  ?>
15
 
16
  <div class="context font-normal text-small">
21
  data-toggle-alt-content="Hide metadata">View metadata</a>
22
  <div id="context-<?php echo $prefix . $context->getId() ?>" class="hidden text-small">
23
  <table>
24
+
25
  <?php foreach($context->getData() as $key => $value):?>
26
  <tr>
27
  <th class="key"><?php echo $key?></th>
app/design/frontend/base/default/template/ecocode_profiler/renderer/table.phtml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /** @var Ecocode_Profiler_Block_Renderer_Table $this */
3
+
4
+ /** @var Ecocode_Profiler_Helper_ValueExporter $valueExport */
5
+ $valueExport = $this->helper('ecocode_profiler/valueExporter');
6
+ $labels = $this->getLabels();
7
+ ?>
8
+ <table class="<?php echo $this->getClass() ?>">
9
+ <thead>
10
+ <tr>
11
+ <th scope="col" class="key"><?php echo isset($labels[0]) ? $labels[0] : 'Key' ?></th>
12
+ <th scope="col" class="key"><?php echo isset($labels[1]) ? $labels[1] : 'Value' ?></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <?php foreach ($this->getItems() as $key => $value): ?>
17
+ <tr>
18
+ <th scope="row"><?php echo $key ?></th>
19
+ <td><?php echo $valueExport->exportValue($value) ?></td>
20
+ </tr>
21
+ <?php endforeach; ?>
22
+ </tbody>
23
+ </table>
app/design/frontend/base/default/template/ecocode_profiler/toolbar_js.phtml CHANGED
@@ -2,6 +2,7 @@
2
  <?php $token = $this->getToken(); ?>
3
 
4
  <div id="sfwdt<?php echo $token?>" class="sf-toolbar" style="display: none"></div>
 
5
  <script>
6
  <?php echo $this->getChildHtml('base_js');?>
7
  (function () {
2
  <?php $token = $this->getToken(); ?>
3
 
4
  <div id="sfwdt<?php echo $token?>" class="sf-toolbar" style="display: none"></div>
5
+ <iframe name="profiler_link_target" class="hidden"></iframe>
6
  <script>
7
  <?php echo $this->getChildHtml('base_js');?>
8
  (function () {
lib/SqlFormatter.php ADDED
@@ -0,0 +1,1080 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SQL Formatter is a collection of utilities for debugging SQL queries.
4
+ * It includes methods for formatting, syntax highlighting, removing comments, etc.
5
+ *
6
+ * @package SqlFormatter
7
+ * @author Jeremy Dorn <jeremy@jeremydorn.com>
8
+ * @author Florin Patan <florinpatan@gmail.com>
9
+ * @copyright 2013 Jeremy Dorn
10
+ * @license http://opensource.org/licenses/MIT
11
+ * @link http://github.com/jdorn/sql-formatter
12
+ * @version 1.2.17
13
+ */
14
+ class SqlFormatter
15
+ {
16
+ // Constants for token types
17
+ const TOKEN_TYPE_WHITESPACE = 0;
18
+ const TOKEN_TYPE_WORD = 1;
19
+ const TOKEN_TYPE_QUOTE = 2;
20
+ const TOKEN_TYPE_BACKTICK_QUOTE = 3;
21
+ const TOKEN_TYPE_RESERVED = 4;
22
+ const TOKEN_TYPE_RESERVED_TOPLEVEL = 5;
23
+ const TOKEN_TYPE_RESERVED_NEWLINE = 6;
24
+ const TOKEN_TYPE_BOUNDARY = 7;
25
+ const TOKEN_TYPE_COMMENT = 8;
26
+ const TOKEN_TYPE_BLOCK_COMMENT = 9;
27
+ const TOKEN_TYPE_NUMBER = 10;
28
+ const TOKEN_TYPE_ERROR = 11;
29
+ const TOKEN_TYPE_VARIABLE = 12;
30
+
31
+ // Constants for different components of a token
32
+ const TOKEN_TYPE = 0;
33
+ const TOKEN_VALUE = 1;
34
+
35
+ // Reserved words (for syntax highlighting)
36
+ protected static $reserved = array(
37
+ 'ACCESSIBLE', 'ACTION', 'AGAINST', 'AGGREGATE', 'ALGORITHM', 'ALL', 'ALTER', 'ANALYSE', 'ANALYZE', 'AS', 'ASC',
38
+ 'AUTOCOMMIT', 'AUTO_INCREMENT', 'BACKUP', 'BEGIN', 'BETWEEN', 'BINLOG', 'BOTH', 'CASCADE', 'CASE', 'CHANGE', 'CHANGED', 'CHARACTER SET',
39
+ 'CHARSET', 'CHECK', 'CHECKSUM', 'COLLATE', 'COLLATION', 'COLUMN', 'COLUMNS', 'COMMENT', 'COMMIT', 'COMMITTED', 'COMPRESSED', 'CONCURRENT',
40
+ 'CONSTRAINT', 'CONTAINS', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_TIMESTAMP', 'DATABASE', 'DATABASES', 'DAY', 'DAY_HOUR', 'DAY_MINUTE',
41
+ 'DAY_SECOND', 'DEFAULT', 'DEFINER', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DIV',
42
+ 'DO', 'DUMPFILE', 'DUPLICATE', 'DYNAMIC', 'ELSE', 'ENCLOSED', 'END', 'ENGINE', 'ENGINE_TYPE', 'ENGINES', 'ESCAPE', 'ESCAPED', 'EVENTS', 'EXECUTE',
43
+ 'EXISTS', 'EXPLAIN', 'EXTENDED', 'FAST', 'FIELDS', 'FILE', 'FIRST', 'FIXED', 'FLUSH', 'FOR', 'FORCE', 'FOREIGN', 'FULL', 'FULLTEXT',
44
+ 'FUNCTION', 'GLOBAL', 'GRANT', 'GRANTS', 'GROUP_CONCAT', 'HEAP', 'HIGH_PRIORITY', 'HOSTS', 'HOUR', 'HOUR_MINUTE',
45
+ 'HOUR_SECOND', 'IDENTIFIED', 'IF', 'IFNULL', 'IGNORE', 'IN', 'INDEX', 'INDEXES', 'INFILE', 'INSERT', 'INSERT_ID', 'INSERT_METHOD', 'INTERVAL',
46
+ 'INTO', 'INVOKER', 'IS', 'ISOLATION', 'KEY', 'KEYS', 'KILL', 'LAST_INSERT_ID', 'LEADING', 'LEVEL', 'LIKE', 'LINEAR',
47
+ 'LINES', 'LOAD', 'LOCAL', 'LOCK', 'LOCKS', 'LOGS', 'LOW_PRIORITY', 'MARIA', 'MASTER', 'MASTER_CONNECT_RETRY', 'MASTER_HOST', 'MASTER_LOG_FILE',
48
+ 'MATCH','MAX_CONNECTIONS_PER_HOUR', 'MAX_QUERIES_PER_HOUR', 'MAX_ROWS', 'MAX_UPDATES_PER_HOUR', 'MAX_USER_CONNECTIONS',
49
+ 'MEDIUM', 'MERGE', 'MINUTE', 'MINUTE_SECOND', 'MIN_ROWS', 'MODE', 'MODIFY',
50
+ 'MONTH', 'MRG_MYISAM', 'MYISAM', 'NAMES', 'NATURAL', 'NOT', 'NOW()','NULL', 'OFFSET', 'ON', 'OPEN', 'OPTIMIZE', 'OPTION', 'OPTIONALLY',
51
+ 'ON UPDATE', 'ON DELETE', 'OUTFILE', 'PACK_KEYS', 'PAGE', 'PARTIAL', 'PARTITION', 'PARTITIONS', 'PASSWORD', 'PRIMARY', 'PRIVILEGES', 'PROCEDURE',
52
+ 'PROCESS', 'PROCESSLIST', 'PURGE', 'QUICK', 'RANGE', 'RAID0', 'RAID_CHUNKS', 'RAID_CHUNKSIZE','RAID_TYPE', 'READ', 'READ_ONLY',
53
+ 'READ_WRITE', 'REFERENCES', 'REGEXP', 'RELOAD', 'RENAME', 'REPAIR', 'REPEATABLE', 'REPLACE', 'REPLICATION', 'RESET', 'RESTORE', 'RESTRICT',
54
+ 'RETURN', 'RETURNS', 'REVOKE', 'RLIKE', 'ROLLBACK', 'ROW', 'ROWS', 'ROW_FORMAT', 'SECOND', 'SECURITY', 'SEPARATOR',
55
+ 'SERIALIZABLE', 'SESSION', 'SHARE', 'SHOW', 'SHUTDOWN', 'SLAVE', 'SONAME', 'SOUNDS', 'SQL', 'SQL_AUTO_IS_NULL', 'SQL_BIG_RESULT',
56
+ 'SQL_BIG_SELECTS', 'SQL_BIG_TABLES', 'SQL_BUFFER_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_LOG_BIN', 'SQL_LOG_OFF', 'SQL_LOG_UPDATE',
57
+ 'SQL_LOW_PRIORITY_UPDATES', 'SQL_MAX_JOIN_SIZE', 'SQL_QUOTE_SHOW_CREATE', 'SQL_SAFE_UPDATES', 'SQL_SELECT_LIMIT', 'SQL_SLAVE_SKIP_COUNTER',
58
+ 'SQL_SMALL_RESULT', 'SQL_WARNINGS', 'SQL_CACHE', 'SQL_NO_CACHE', 'START', 'STARTING', 'STATUS', 'STOP', 'STORAGE',
59
+ 'STRAIGHT_JOIN', 'STRING', 'STRIPED', 'SUPER', 'TABLE', 'TABLES', 'TEMPORARY', 'TERMINATED', 'THEN', 'TO', 'TRAILING', 'TRANSACTIONAL', 'TRUE',
60
+ 'TRUNCATE', 'TYPE', 'TYPES', 'UNCOMMITTED', 'UNIQUE', 'UNLOCK', 'UNSIGNED', 'USAGE', 'USE', 'USING', 'VARIABLES',
61
+ 'VIEW', 'WHEN', 'WITH', 'WORK', 'WRITE', 'YEAR_MONTH'
62
+ );
63
+
64
+ // For SQL formatting
65
+ // These keywords will all be on their own line
66
+ protected static $reserved_toplevel = array(
67
+ 'SELECT', 'FROM', 'WHERE', 'SET', 'ORDER BY', 'GROUP BY', 'LIMIT', 'DROP',
68
+ 'VALUES', 'UPDATE', 'HAVING', 'ADD', 'AFTER', 'ALTER TABLE', 'DELETE FROM', 'UNION ALL', 'UNION', 'EXCEPT', 'INTERSECT'
69
+ );
70
+
71
+ protected static $reserved_newline = array(
72
+ 'LEFT OUTER JOIN', 'RIGHT OUTER JOIN', 'LEFT JOIN', 'RIGHT JOIN', 'OUTER JOIN', 'INNER JOIN', 'JOIN', 'XOR', 'OR', 'AND'
73
+ );
74
+
75
+ protected static $functions = array (
76
+ 'ABS', 'ACOS', 'ADDDATE', 'ADDTIME', 'AES_DECRYPT', 'AES_ENCRYPT', 'AREA', 'ASBINARY', 'ASCII', 'ASIN', 'ASTEXT', 'ATAN', 'ATAN2',
77
+ 'AVG', 'BDMPOLYFROMTEXT', 'BDMPOLYFROMWKB', 'BDPOLYFROMTEXT', 'BDPOLYFROMWKB', 'BENCHMARK', 'BIN', 'BIT_AND', 'BIT_COUNT', 'BIT_LENGTH',
78
+ 'BIT_OR', 'BIT_XOR', 'BOUNDARY', 'BUFFER', 'CAST', 'CEIL', 'CEILING', 'CENTROID', 'CHAR', 'CHARACTER_LENGTH', 'CHARSET', 'CHAR_LENGTH',
79
+ 'COALESCE', 'COERCIBILITY', 'COLLATION', 'COMPRESS', 'CONCAT', 'CONCAT_WS', 'CONNECTION_ID', 'CONTAINS', 'CONV', 'CONVERT', 'CONVERT_TZ',
80
+ 'CONVEXHULL', 'COS', 'COT', 'COUNT', 'CRC32', 'CROSSES', 'CURDATE', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER',
81
+ 'CURTIME', 'DATABASE', 'DATE', 'DATEDIFF', 'DATE_ADD', 'DATE_DIFF', 'DATE_FORMAT', 'DATE_SUB', 'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK',
82
+ 'DAYOFYEAR', 'DECODE', 'DEFAULT', 'DEGREES', 'DES_DECRYPT', 'DES_ENCRYPT', 'DIFFERENCE', 'DIMENSION', 'DISJOINT', 'DISTANCE', 'ELT', 'ENCODE',
83
+ 'ENCRYPT', 'ENDPOINT', 'ENVELOPE', 'EQUALS', 'EXP', 'EXPORT_SET', 'EXTERIORRING', 'EXTRACT', 'EXTRACTVALUE', 'FIELD', 'FIND_IN_SET', 'FLOOR',
84
+ 'FORMAT', 'FOUND_ROWS', 'FROM_DAYS', 'FROM_UNIXTIME', 'GEOMCOLLFROMTEXT', 'GEOMCOLLFROMWKB', 'GEOMETRYCOLLECTION', 'GEOMETRYCOLLECTIONFROMTEXT',
85
+ 'GEOMETRYCOLLECTIONFROMWKB', 'GEOMETRYFROMTEXT', 'GEOMETRYFROMWKB', 'GEOMETRYN', 'GEOMETRYTYPE', 'GEOMFROMTEXT', 'GEOMFROMWKB', 'GET_FORMAT',
86
+ 'GET_LOCK', 'GLENGTH', 'GREATEST', 'GROUP_CONCAT', 'GROUP_UNIQUE_USERS', 'HEX', 'HOUR', 'IF', 'IFNULL', 'INET_ATON', 'INET_NTOA', 'INSERT', 'INSTR',
87
+ 'INTERIORRINGN', 'INTERSECTION', 'INTERSECTS', 'INTERVAL', 'ISCLOSED', 'ISEMPTY', 'ISNULL', 'ISRING', 'ISSIMPLE', 'IS_FREE_LOCK', 'IS_USED_LOCK',
88
+ 'LAST_DAY', 'LAST_INSERT_ID', 'LCASE', 'LEAST', 'LEFT', 'LENGTH', 'LINEFROMTEXT', 'LINEFROMWKB', 'LINESTRING', 'LINESTRINGFROMTEXT', 'LINESTRINGFROMWKB',
89
+ 'LN', 'LOAD_FILE', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCATE', 'LOG', 'LOG10', 'LOG2', 'LOWER', 'LPAD', 'LTRIM', 'MAKEDATE', 'MAKETIME', 'MAKE_SET',
90
+ 'MASTER_POS_WAIT', 'MAX', 'MBRCONTAINS', 'MBRDISJOINT', 'MBREQUAL', 'MBRINTERSECTS', 'MBROVERLAPS', 'MBRTOUCHES', 'MBRWITHIN', 'MD5', 'MICROSECOND',
91
+ 'MID', 'MIN', 'MINUTE', 'MLINEFROMTEXT', 'MLINEFROMWKB', 'MOD', 'MONTH', 'MONTHNAME', 'MPOINTFROMTEXT', 'MPOINTFROMWKB', 'MPOLYFROMTEXT', 'MPOLYFROMWKB',
92
+ 'MULTILINESTRING', 'MULTILINESTRINGFROMTEXT', 'MULTILINESTRINGFROMWKB', 'MULTIPOINT', 'MULTIPOINTFROMTEXT', 'MULTIPOINTFROMWKB', 'MULTIPOLYGON',
93
+ 'MULTIPOLYGONFROMTEXT', 'MULTIPOLYGONFROMWKB', 'NAME_CONST', 'NULLIF', 'NUMGEOMETRIES', 'NUMINTERIORRINGS', 'NUMPOINTS', 'OCT', 'OCTET_LENGTH',
94
+ 'OLD_PASSWORD', 'ORD', 'OVERLAPS', 'PASSWORD', 'PERIOD_ADD', 'PERIOD_DIFF', 'PI', 'POINT', 'POINTFROMTEXT', 'POINTFROMWKB', 'POINTN', 'POINTONSURFACE',
95
+ 'POLYFROMTEXT', 'POLYFROMWKB', 'POLYGON', 'POLYGONFROMTEXT', 'POLYGONFROMWKB', 'POSITION', 'POW', 'POWER', 'QUARTER', 'QUOTE', 'RADIANS', 'RAND',
96
+ 'RELATED', 'RELEASE_LOCK', 'REPEAT', 'REPLACE', 'REVERSE', 'RIGHT', 'ROUND', 'ROW_COUNT', 'RPAD', 'RTRIM', 'SCHEMA', 'SECOND', 'SEC_TO_TIME',
97
+ 'SESSION_USER', 'SHA', 'SHA1', 'SIGN', 'SIN', 'SLEEP', 'SOUNDEX', 'SPACE', 'SQRT', 'SRID', 'STARTPOINT', 'STD', 'STDDEV', 'STDDEV_POP', 'STDDEV_SAMP',
98
+ 'STRCMP', 'STR_TO_DATE', 'SUBDATE', 'SUBSTR', 'SUBSTRING', 'SUBSTRING_INDEX', 'SUBTIME', 'SUM', 'SYMDIFFERENCE', 'SYSDATE', 'SYSTEM_USER', 'TAN',
99
+ 'TIME', 'TIMEDIFF', 'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TIME_FORMAT', 'TIME_TO_SEC', 'TOUCHES', 'TO_DAYS', 'TRIM', 'TRUNCATE', 'UCASE',
100
+ 'UNCOMPRESS', 'UNCOMPRESSED_LENGTH', 'UNHEX', 'UNIQUE_USERS', 'UNIX_TIMESTAMP', 'UPDATEXML', 'UPPER', 'USER', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP',
101
+ 'UUID', 'VARIANCE', 'VAR_POP', 'VAR_SAMP', 'VERSION', 'WEEK', 'WEEKDAY', 'WEEKOFYEAR', 'WITHIN', 'X', 'Y', 'YEAR', 'YEARWEEK'
102
+ );
103
+
104
+ // Punctuation that can be used as a boundary between other tokens
105
+ protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
106
+
107
+ // For HTML syntax highlighting
108
+ // Styles applied to different token types
109
+ public static $quote_attributes = 'style="color: blue;"';
110
+ public static $backtick_quote_attributes = 'style="color: purple;"';
111
+ public static $reserved_attributes = 'style="font-weight:bold;"';
112
+ public static $boundary_attributes = '';
113
+ public static $number_attributes = 'style="color: green;"';
114
+ public static $word_attributes = 'style="color: #333;"';
115
+ public static $error_attributes = 'style="background-color: red;"';
116
+ public static $comment_attributes = 'style="color: #aaa;"';
117
+ public static $variable_attributes = 'style="color: orange;"';
118
+ public static $pre_attributes = 'style="color: black; background-color: white;"';
119
+
120
+ // Boolean - whether or not the current environment is the CLI
121
+ // This affects the type of syntax highlighting
122
+ // If not defined, it will be determined automatically
123
+ public static $cli;
124
+
125
+ // For CLI syntax highlighting
126
+ public static $cli_quote = "\x1b[34;1m";
127
+ public static $cli_backtick_quote = "\x1b[35;1m";
128
+ public static $cli_reserved = "\x1b[37m";
129
+ public static $cli_boundary = "";
130
+ public static $cli_number = "\x1b[32;1m";
131
+ public static $cli_word = "";
132
+ public static $cli_error = "\x1b[31;1;7m";
133
+ public static $cli_comment = "\x1b[30;1m";
134
+ public static $cli_functions = "\x1b[37m";
135
+ public static $cli_variable = "\x1b[36;1m";
136
+
137
+ // The tab character to use when formatting SQL
138
+ public static $tab = ' ';
139
+
140
+ // This flag tells us if queries need to be enclosed in <pre> tags
141
+ public static $use_pre = true;
142
+
143
+ // This flag tells us if SqlFormatted has been initialized
144
+ protected static $init;
145
+
146
+ // Regular expressions for tokenizing
147
+ protected static $regex_boundaries;
148
+ protected static $regex_reserved;
149
+ protected static $regex_reserved_newline;
150
+ protected static $regex_reserved_toplevel;
151
+ protected static $regex_function;
152
+
153
+ // Cache variables
154
+ // Only tokens shorter than this size will be cached. Somewhere between 10 and 20 seems to work well for most cases.
155
+ public static $max_cachekey_size = 15;
156
+ protected static $token_cache = array();
157
+ protected static $cache_hits = 0;
158
+ protected static $cache_misses = 0;
159
+
160
+ /**
161
+ * Get stats about the token cache
162
+ * @return Array An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes
163
+ */
164
+ public static function getCacheStats()
165
+ {
166
+ return array(
167
+ 'hits'=>self::$cache_hits,
168
+ 'misses'=>self::$cache_misses,
169
+ 'entries'=>count(self::$token_cache),
170
+ 'size'=>strlen(serialize(self::$token_cache))
171
+ );
172
+ }
173
+
174
+ /**
175
+ * Stuff that only needs to be done once. Builds regular expressions and sorts the reserved words.
176
+ */
177
+ protected static function init()
178
+ {
179
+ if (self::$init) return;
180
+
181
+ // Sort reserved word list from longest word to shortest, 3x faster than usort
182
+ $reservedMap = array_combine(self::$reserved, array_map('strlen', self::$reserved));
183
+ arsort($reservedMap);
184
+ self::$reserved = array_keys($reservedMap);
185
+
186
+ // Set up regular expressions
187
+ self::$regex_boundaries = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$boundaries)).')';
188
+ self::$regex_reserved = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved)).')';
189
+ self::$regex_reserved_toplevel = str_replace(' ','\\s+','('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved_toplevel)).')');
190
+ self::$regex_reserved_newline = str_replace(' ','\\s+','('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved_newline)).')');
191
+
192
+ self::$regex_function = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$functions)).')';
193
+
194
+ self::$init = true;
195
+ }
196
+
197
+ /**
198
+ * Return the next token and token type in a SQL string.
199
+ * Quoted strings, comments, reserved words, whitespace, and punctuation are all their own tokens.
200
+ *
201
+ * @param String $string The SQL string
202
+ * @param array $previous The result of the previous getNextToken() call
203
+ *
204
+ * @return Array An associative array containing the type and value of the token.
205
+ */
206
+ protected static function getNextToken($string, $previous = null)
207
+ {
208
+ // Whitespace
209
+ if (preg_match('/^\s+/',$string,$matches)) {
210
+ return array(
211
+ self::TOKEN_VALUE => $matches[0],
212
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_WHITESPACE
213
+ );
214
+ }
215
+
216
+ // Comment
217
+ if ($string[0] === '#' || (isset($string[1])&&($string[0]==='-'&&$string[1]==='-') || ($string[0]==='/'&&$string[1]==='*'))) {
218
+ // Comment until end of line
219
+ if ($string[0] === '-' || $string[0] === '#') {
220
+ $last = strpos($string, "\n");
221
+ $type = self::TOKEN_TYPE_COMMENT;
222
+ } else { // Comment until closing comment tag
223
+ $last = strpos($string, "*/", 2) + 2;
224
+ $type = self::TOKEN_TYPE_BLOCK_COMMENT;
225
+ }
226
+
227
+ if ($last === false) {
228
+ $last = strlen($string);
229
+ }
230
+
231
+ return array(
232
+ self::TOKEN_VALUE => substr($string, 0, $last),
233
+ self::TOKEN_TYPE => $type
234
+ );
235
+ }
236
+
237
+ // Quoted String
238
+ if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`') {
239
+ $return = array(
240
+ self::TOKEN_TYPE => ($string[0]==='`'? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE),
241
+ self::TOKEN_VALUE => self::getQuotedString($string)
242
+ );
243
+
244
+ return $return;
245
+ }
246
+
247
+ // User-defined Variable
248
+ if ($string[0] === '@' && isset($string[1])) {
249
+ $ret = array(
250
+ self::TOKEN_VALUE => null,
251
+ self::TOKEN_TYPE => self::TOKEN_TYPE_VARIABLE
252
+ );
253
+
254
+ // If the variable name is quoted
255
+ if ($string[1]==='"' || $string[1]==='\'' || $string[1]==='`') {
256
+ $ret[self::TOKEN_VALUE] = '@'.self::getQuotedString(substr($string,1));
257
+ }
258
+ // Non-quoted variable name
259
+ else {
260
+ preg_match('/^(@[a-zA-Z0-9\._\$]+)/',$string,$matches);
261
+ if ($matches) {
262
+ $ret[self::TOKEN_VALUE] = $matches[1];
263
+ }
264
+ }
265
+
266
+ if($ret[self::TOKEN_VALUE] !== null) return $ret;
267
+ }
268
+
269
+ // Number (decimal, binary, or hex)
270
+ if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|'.self::$regex_boundaries.')/',$string,$matches)) {
271
+ return array(
272
+ self::TOKEN_VALUE => $matches[1],
273
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_NUMBER
274
+ );
275
+ }
276
+
277
+ // Boundary Character (punctuation and symbols)
278
+ if (preg_match('/^('.self::$regex_boundaries.')/',$string,$matches)) {
279
+ return array(
280
+ self::TOKEN_VALUE => $matches[1],
281
+ self::TOKEN_TYPE => self::TOKEN_TYPE_BOUNDARY
282
+ );
283
+ }
284
+
285
+ // A reserved word cannot be preceded by a '.'
286
+ // this makes it so in "mytable.from", "from" is not considered a reserved word
287
+ if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
288
+ $upper = strtoupper($string);
289
+ // Top Level Reserved Word
290
+ if (preg_match('/^('.self::$regex_reserved_toplevel.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) {
291
+ return array(
292
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED_TOPLEVEL,
293
+ self::TOKEN_VALUE=>substr($string,0,strlen($matches[1]))
294
+ );
295
+ }
296
+ // Newline Reserved Word
297
+ if (preg_match('/^('.self::$regex_reserved_newline.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) {
298
+ return array(
299
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED_NEWLINE,
300
+ self::TOKEN_VALUE=>substr($string,0,strlen($matches[1]))
301
+ );
302
+ }
303
+ // Other Reserved Word
304
+ if (preg_match('/^('.self::$regex_reserved.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) {
305
+ return array(
306
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED,
307
+ self::TOKEN_VALUE=>substr($string,0,strlen($matches[1]))
308
+ );
309
+ }
310
+ }
311
+
312
+ // A function must be suceeded by '('
313
+ // this makes it so "count(" is considered a function, but "count" alone is not
314
+ $upper = strtoupper($string);
315
+ // function
316
+ if (preg_match('/^('.self::$regex_function.'[(]|\s|[)])/', $upper,$matches)) {
317
+ return array(
318
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED,
319
+ self::TOKEN_VALUE=>substr($string,0,strlen($matches[1])-1)
320
+ );
321
+ }
322
+
323
+ // Non reserved word
324
+ preg_match('/^(.*?)($|\s|["\'`]|'.self::$regex_boundaries.')/',$string,$matches);
325
+
326
+ return array(
327
+ self::TOKEN_VALUE => $matches[1],
328
+ self::TOKEN_TYPE => self::TOKEN_TYPE_WORD
329
+ );
330
+ }
331
+
332
+ protected static function getQuotedString($string)
333
+ {
334
+ $ret = null;
335
+
336
+ // This checks for the following patterns:
337
+ // 1. backtick quoted string using `` to escape
338
+ // 2. double quoted string using "" or \" to escape
339
+ // 3. single quoted string using '' or \' to escape
340
+ if ( preg_match('/^(((`[^`]*($|`))+)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) {
341
+ $ret = $matches[1];
342
+ }
343
+
344
+ return $ret;
345
+ }
346
+
347
+ /**
348
+ * Takes a SQL string and breaks it into tokens.
349
+ * Each token is an associative array with type and value.
350
+ *
351
+ * @param String $string The SQL string
352
+ *
353
+ * @return Array An array of tokens.
354
+ */
355
+ protected static function tokenize($string)
356
+ {
357
+ self::init();
358
+
359
+ $tokens = array();
360
+
361
+ // Used for debugging if there is an error while tokenizing the string
362
+ $original_length = strlen($string);
363
+
364
+ // Used to make sure the string keeps shrinking on each iteration
365
+ $old_string_len = strlen($string) + 1;
366
+
367
+ $token = null;
368
+
369
+ $current_length = strlen($string);
370
+
371
+ // Keep processing the string until it is empty
372
+ while ($current_length) {
373
+ // If the string stopped shrinking, there was a problem
374
+ if ($old_string_len <= $current_length) {
375
+ $tokens[] = array(
376
+ self::TOKEN_VALUE=>$string,
377
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_ERROR
378
+ );
379
+
380
+ return $tokens;
381
+ }
382
+ $old_string_len = $current_length;
383
+
384
+ // Determine if we can use caching
385
+ if ($current_length >= self::$max_cachekey_size) {
386
+ $cacheKey = substr($string,0,self::$max_cachekey_size);
387
+ } else {
388
+ $cacheKey = false;
389
+ }
390
+
391
+ // See if the token is already cached
392
+ if ($cacheKey && isset(self::$token_cache[$cacheKey])) {
393
+ // Retrieve from cache
394
+ $token = self::$token_cache[$cacheKey];
395
+ $token_length = strlen($token[self::TOKEN_VALUE]);
396
+ self::$cache_hits++;
397
+ } else {
398
+ // Get the next token and the token type
399
+ $token = self::getNextToken($string, $token);
400
+ $token_length = strlen($token[self::TOKEN_VALUE]);
401
+ self::$cache_misses++;
402
+
403
+ // If the token is shorter than the max length, store it in cache
404
+ if ($cacheKey && $token_length < self::$max_cachekey_size) {
405
+ self::$token_cache[$cacheKey] = $token;
406
+ }
407
+ }
408
+
409
+ $tokens[] = $token;
410
+
411
+ // Advance the string
412
+ $string = substr($string, $token_length);
413
+
414
+ $current_length -= $token_length;
415
+ }
416
+
417
+ return $tokens;
418
+ }
419
+
420
+ /**
421
+ * Format the whitespace in a SQL string to make it easier to read.
422
+ *
423
+ * @param String $string The SQL string
424
+ * @param boolean $highlight If true, syntax highlighting will also be performed
425
+ *
426
+ * @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag
427
+ */
428
+ public static function format($string, $highlight=true)
429
+ {
430
+ // This variable will be populated with formatted html
431
+ $return = '';
432
+
433
+ // Use an actual tab while formatting and then switch out with self::$tab at the end
434
+ $tab = "\t";
435
+
436
+ $indent_level = 0;
437
+ $newline = false;
438
+ $inline_parentheses = false;
439
+ $increase_special_indent = false;
440
+ $increase_block_indent = false;
441
+ $indent_types = array();
442
+ $added_newline = false;
443
+ $inline_count = 0;
444
+ $inline_indented = false;
445
+ $clause_limit = false;
446
+
447
+ // Tokenize String
448
+ $original_tokens = self::tokenize($string);
449
+
450
+ // Remove existing whitespace
451
+ $tokens = array();
452
+ foreach ($original_tokens as $i=>$token) {
453
+ if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
454
+ $token['i'] = $i;
455
+ $tokens[] = $token;
456
+ }
457
+ }
458
+
459
+ // Format token by token
460
+ foreach ($tokens as $i=>$token) {
461
+ // Get highlighted token if doing syntax highlighting
462
+ if ($highlight) {
463
+ $highlighted = self::highlightToken($token);
464
+ } else { // If returning raw text
465
+ $highlighted = $token[self::TOKEN_VALUE];
466
+ }
467
+
468
+ // If we are increasing the special indent level now
469
+ if ($increase_special_indent) {
470
+ $indent_level++;
471
+ $increase_special_indent = false;
472
+ array_unshift($indent_types,'special');
473
+ }
474
+ // If we are increasing the block indent level now
475
+ if ($increase_block_indent) {
476
+ $indent_level++;
477
+ $increase_block_indent = false;
478
+ array_unshift($indent_types,'block');
479
+ }
480
+
481
+ // If we need a new line before the token
482
+ if ($newline) {
483
+ $return .= "\n" . str_repeat($tab, $indent_level);
484
+ $newline = false;
485
+ $added_newline = true;
486
+ } else {
487
+ $added_newline = false;
488
+ }
489
+
490
+ // Display comments directly where they appear in the source
491
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
492
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
493
+ $indent = str_repeat($tab,$indent_level);
494
+ $return .= "\n" . $indent;
495
+ $highlighted = str_replace("\n","\n".$indent,$highlighted);
496
+ }
497
+
498
+ $return .= $highlighted;
499
+ $newline = true;
500
+ continue;
501
+ }
502
+
503
+ if ($inline_parentheses) {
504
+ // End of inline parentheses
505
+ if ($token[self::TOKEN_VALUE] === ')') {
506
+ $return = rtrim($return,' ');
507
+
508
+ if ($inline_indented) {
509
+ array_shift($indent_types);
510
+ $indent_level --;
511
+ $return .= "\n" . str_repeat($tab, $indent_level);
512
+ }
513
+
514
+ $inline_parentheses = false;
515
+
516
+ $return .= $highlighted . ' ';
517
+ continue;
518
+ }
519
+
520
+ if ($token[self::TOKEN_VALUE] === ',') {
521
+ if ($inline_count >= 30) {
522
+ $inline_count = 0;
523
+ $newline = true;
524
+ }
525
+ }
526
+
527
+ $inline_count += strlen($token[self::TOKEN_VALUE]);
528
+ }
529
+
530
+ // Opening parentheses increase the block indent level and start a new line
531
+ if ($token[self::TOKEN_VALUE] === '(') {
532
+ // First check if this should be an inline parentheses block
533
+ // Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2)
534
+ // Allow up to 3 non-whitespace tokens inside inline parentheses
535
+ $length = 0;
536
+ for ($j=1;$j<=250;$j++) {
537
+ // Reached end of string
538
+ if (!isset($tokens[$i+$j])) break;
539
+
540
+ $next = $tokens[$i+$j];
541
+
542
+ // Reached closing parentheses, able to inline it
543
+ if ($next[self::TOKEN_VALUE] === ')') {
544
+ $inline_parentheses = true;
545
+ $inline_count = 0;
546
+ $inline_indented = false;
547
+ break;
548
+ }
549
+
550
+ // Reached an invalid token for inline parentheses
551
+ if ($next[self::TOKEN_VALUE]===';' || $next[self::TOKEN_VALUE]==='(') {
552
+ break;
553
+ }
554
+
555
+ // Reached an invalid token type for inline parentheses
556
+ if ($next[self::TOKEN_TYPE]===self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE]===self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE]===self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE]===self::TOKEN_TYPE_BLOCK_COMMENT) {
557
+ break;
558
+ }
559
+
560
+ $length += strlen($next[self::TOKEN_VALUE]);
561
+ }
562
+
563
+ if ($inline_parentheses && $length > 30) {
564
+ $increase_block_indent = true;
565
+ $inline_indented = true;
566
+ $newline = true;
567
+ }
568
+
569
+ // Take out the preceding space unless there was whitespace there in the original query
570
+ if (isset($original_tokens[$token['i']-1]) && $original_tokens[$token['i']-1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
571
+ $return = rtrim($return,' ');
572
+ }
573
+
574
+ if (!$inline_parentheses) {
575
+ $increase_block_indent = true;
576
+ // Add a newline after the parentheses
577
+ $newline = true;
578
+ }
579
+
580
+ }
581
+
582
+ // Closing parentheses decrease the block indent level
583
+ elseif ($token[self::TOKEN_VALUE] === ')') {
584
+ // Remove whitespace before the closing parentheses
585
+ $return = rtrim($return,' ');
586
+
587
+ $indent_level--;
588
+
589
+ // Reset indent level
590
+ while ($j=array_shift($indent_types)) {
591
+ if ($j==='special') {
592
+ $indent_level--;
593
+ } else {
594
+ break;
595
+ }
596
+ }
597
+
598
+ if ($indent_level < 0) {
599
+ // This is an error
600
+ $indent_level = 0;
601
+
602
+ if ($highlight) {
603
+ $return .= "\n".self::highlightError($token[self::TOKEN_VALUE]);
604
+ continue;
605
+ }
606
+ }
607
+
608
+ // Add a newline before the closing parentheses (if not already added)
609
+ if (!$added_newline) {
610
+ $return .= "\n" . str_repeat($tab, $indent_level);
611
+ }
612
+ }
613
+
614
+ // Top level reserved words start a new line and increase the special indent level
615
+ elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
616
+ $increase_special_indent = true;
617
+
618
+ // If the last indent type was 'special', decrease the special indent for this round
619
+ reset($indent_types);
620
+ if (current($indent_types)==='special') {
621
+ $indent_level--;
622
+ array_shift($indent_types);
623
+ }
624
+
625
+ // Add a newline after the top level reserved word
626
+ $newline = true;
627
+ // Add a newline before the top level reserved word (if not already added)
628
+ if (!$added_newline) {
629
+ $return .= "\n" . str_repeat($tab, $indent_level);
630
+ }
631
+ // If we already added a newline, redo the indentation since it may be different now
632
+ else {
633
+ $return = rtrim($return,$tab).str_repeat($tab, $indent_level);
634
+ }
635
+
636
+ // If the token may have extra whitespace
637
+ if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) {
638
+ $highlighted = preg_replace('/\s+/',' ',$highlighted);
639
+ }
640
+ //if SQL 'LIMIT' clause, start variable to reset newline
641
+ if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
642
+ $clause_limit = true;
643
+ }
644
+ }
645
+
646
+ // Checks if we are out of the limit clause
647
+ elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
648
+ $clause_limit = false;
649
+ }
650
+
651
+ // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause)
652
+ elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
653
+ //If the previous TOKEN_VALUE is 'LIMIT', resets new line
654
+ if ($clause_limit === true) {
655
+ $newline = false;
656
+ $clause_limit = false;
657
+ }
658
+ // All other cases of commas
659
+ else {
660
+ $newline = true;
661
+ }
662
+ }
663
+
664
+ // Newline reserved words start a new line
665
+ elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
666
+ // Add a newline before the reserved word (if not already added)
667
+ if (!$added_newline) {
668
+ $return .= "\n" . str_repeat($tab, $indent_level);
669
+ }
670
+
671
+ // If the token may have extra whitespace
672
+ if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) {
673
+ $highlighted = preg_replace('/\s+/',' ',$highlighted);
674
+ }
675
+ }
676
+
677
+ // Multiple boundary characters in a row should not have spaces between them (not including parentheses)
678
+ elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
679
+ if (isset($tokens[$i-1]) && $tokens[$i-1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
680
+ if (isset($original_tokens[$token['i']-1]) && $original_tokens[$token['i']-1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
681
+ $return = rtrim($return,' ');
682
+ }
683
+ }
684
+ }
685
+
686
+ // If the token shouldn't have a space before it
687
+ if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') {
688
+ $return = rtrim($return, ' ');
689
+ }
690
+
691
+ $return .= $highlighted.' ';
692
+
693
+ // If the token shouldn't have a space after it
694
+ if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
695
+ $return = rtrim($return,' ');
696
+ }
697
+
698
+ // If this is the "-" of a negative number, it shouldn't have a space after it
699
+ if($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i+1]) && $tokens[$i+1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i-1])) {
700
+ $prev = $tokens[$i-1][self::TOKEN_TYPE];
701
+ if($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
702
+ $return = rtrim($return,' ');
703
+ }
704
+ }
705
+ }
706
+
707
+ // If there are unmatched parentheses
708
+ if ($highlight && array_search('block',$indent_types) !== false) {
709
+ $return .= "\n".self::highlightError("WARNING: unclosed parentheses or section");
710
+ }
711
+
712
+ // Replace tab characters with the configuration tab character
713
+ $return = trim(str_replace("\t",self::$tab,$return));
714
+
715
+ if ($highlight) {
716
+ $return = self::output($return);
717
+ }
718
+
719
+ return $return;
720
+ }
721
+
722
+ /**
723
+ * Add syntax highlighting to a SQL string
724
+ *
725
+ * @param String $string The SQL string
726
+ *
727
+ * @return String The SQL string with HTML styles applied
728
+ */
729
+ public static function highlight($string)
730
+ {
731
+ $tokens = self::tokenize($string);
732
+
733
+ $return = '';
734
+
735
+ foreach ($tokens as $token) {
736
+ $return .= self::highlightToken($token);
737
+ }
738
+
739
+ return self::output($return);
740
+ }
741
+
742
+ /**
743
+ * Split a SQL string into multiple queries.
744
+ * Uses ";" as a query delimiter.
745
+ *
746
+ * @param String $string The SQL string
747
+ *
748
+ * @return Array An array of individual query strings without trailing semicolons
749
+ */
750
+ public static function splitQuery($string)
751
+ {
752
+ $queries = array();
753
+ $current_query = '';
754
+ $empty = true;
755
+
756
+ $tokens = self::tokenize($string);
757
+
758
+ foreach ($tokens as $token) {
759
+ // If this is a query separator
760
+ if ($token[self::TOKEN_VALUE] === ';') {
761
+ if (!$empty) {
762
+ $queries[] = $current_query.';';
763
+ }
764
+ $current_query = '';
765
+ $empty = true;
766
+ continue;
767
+ }
768
+
769
+ // If this is a non-empty character
770
+ if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
771
+ $empty = false;
772
+ }
773
+
774
+ $current_query .= $token[self::TOKEN_VALUE];
775
+ }
776
+
777
+ if (!$empty) {
778
+ $queries[] = trim($current_query);
779
+ }
780
+
781
+ return $queries;
782
+ }
783
+
784
+ /**
785
+ * Remove all comments from a SQL string
786
+ *
787
+ * @param String $string The SQL string
788
+ *
789
+ * @return String The SQL string without comments
790
+ */
791
+ public static function removeComments($string)
792
+ {
793
+ $result = '';
794
+
795
+ $tokens = self::tokenize($string);
796
+
797
+ foreach ($tokens as $token) {
798
+ // Skip comment tokens
799
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
800
+ continue;
801
+ }
802
+
803
+ $result .= $token[self::TOKEN_VALUE];
804
+ }
805
+ $result = self::format( $result,false);
806
+
807
+ return $result;
808
+ }
809
+
810
+ /**
811
+ * Compress a query by collapsing white space and removing comments
812
+ *
813
+ * @param String $string The SQL string
814
+ *
815
+ * @return String The SQL string without comments
816
+ */
817
+ public static function compress($string)
818
+ {
819
+ $result = '';
820
+
821
+ $tokens = self::tokenize($string);
822
+
823
+ $whitespace = true;
824
+ foreach ($tokens as $token) {
825
+ // Skip comment tokens
826
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
827
+ continue;
828
+ }
829
+ // Remove extra whitespace in reserved words (e.g "OUTER JOIN" becomes "OUTER JOIN")
830
+ elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
831
+ $token[self::TOKEN_VALUE] = preg_replace('/\s+/',' ',$token[self::TOKEN_VALUE]);
832
+ }
833
+
834
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
835
+ // If the last token was whitespace, don't add another one
836
+ if ($whitespace) {
837
+ continue;
838
+ } else {
839
+ $whitespace = true;
840
+ // Convert all whitespace to a single space
841
+ $token[self::TOKEN_VALUE] = ' ';
842
+ }
843
+ } else {
844
+ $whitespace = false;
845
+ }
846
+
847
+ $result .= $token[self::TOKEN_VALUE];
848
+ }
849
+
850
+ return rtrim($result);
851
+ }
852
+
853
+ /**
854
+ * Highlights a token depending on its type.
855
+ *
856
+ * @param Array $token An associative array containing type and value.
857
+ *
858
+ * @return String HTML code of the highlighted token.
859
+ */
860
+ protected static function highlightToken($token)
861
+ {
862
+ $type = $token[self::TOKEN_TYPE];
863
+
864
+ if (self::is_cli()) {
865
+ $token = $token[self::TOKEN_VALUE];
866
+ } else {
867
+ $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT,'UTF-8');
868
+ }
869
+
870
+ if ($type===self::TOKEN_TYPE_BOUNDARY) {
871
+ return self::highlightBoundary($token);
872
+ } elseif ($type===self::TOKEN_TYPE_WORD) {
873
+ return self::highlightWord($token);
874
+ } elseif ($type===self::TOKEN_TYPE_BACKTICK_QUOTE) {
875
+ return self::highlightBacktickQuote($token);
876
+ } elseif ($type===self::TOKEN_TYPE_QUOTE) {
877
+ return self::highlightQuote($token);
878
+ } elseif ($type===self::TOKEN_TYPE_RESERVED) {
879
+ return self::highlightReservedWord($token);
880
+ } elseif ($type===self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
881
+ return self::highlightReservedWord($token);
882
+ } elseif ($type===self::TOKEN_TYPE_RESERVED_NEWLINE) {
883
+ return self::highlightReservedWord($token);
884
+ } elseif ($type===self::TOKEN_TYPE_NUMBER) {
885
+ return self::highlightNumber($token);
886
+ } elseif ($type===self::TOKEN_TYPE_VARIABLE) {
887
+ return self::highlightVariable($token);
888
+ } elseif ($type===self::TOKEN_TYPE_COMMENT || $type===self::TOKEN_TYPE_BLOCK_COMMENT) {
889
+ return self::highlightComment($token);
890
+ }
891
+
892
+ return $token;
893
+ }
894
+
895
+ /**
896
+ * Highlights a quoted string
897
+ *
898
+ * @param String $value The token's value
899
+ *
900
+ * @return String HTML code of the highlighted token.
901
+ */
902
+ protected static function highlightQuote($value)
903
+ {
904
+ if (self::is_cli()) {
905
+ return self::$cli_quote . $value . "\x1b[0m";
906
+ } else {
907
+ return '<span ' . self::$quote_attributes . '>' . $value . '</span>';
908
+ }
909
+ }
910
+
911
+ /**
912
+ * Highlights a backtick quoted string
913
+ *
914
+ * @param String $value The token's value
915
+ *
916
+ * @return String HTML code of the highlighted token.
917
+ */
918
+ protected static function highlightBacktickQuote($value)
919
+ {
920
+ if (self::is_cli()) {
921
+ return self::$cli_backtick_quote . $value . "\x1b[0m";
922
+ } else {
923
+ return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>';
924
+ }
925
+ }
926
+
927
+ /**
928
+ * Highlights a reserved word
929
+ *
930
+ * @param String $value The token's value
931
+ *
932
+ * @return String HTML code of the highlighted token.
933
+ */
934
+ protected static function highlightReservedWord($value)
935
+ {
936
+ if (self::is_cli()) {
937
+ return self::$cli_reserved . $value . "\x1b[0m";
938
+ } else {
939
+ return '<span ' . self::$reserved_attributes . '>' . $value . '</span>';
940
+ }
941
+ }
942
+
943
+ /**
944
+ * Highlights a boundary token
945
+ *
946
+ * @param String $value The token's value
947
+ *
948
+ * @return String HTML code of the highlighted token.
949
+ */
950
+ protected static function highlightBoundary($value)
951
+ {
952
+ if ($value==='(' || $value===')') return $value;
953
+
954
+ if (self::is_cli()) {
955
+ return self::$cli_boundary . $value . "\x1b[0m";
956
+ } else {
957
+ return '<span ' . self::$boundary_attributes . '>' . $value . '</span>';
958
+ }
959
+ }
960
+
961
+ /**
962
+ * Highlights a number
963
+ *
964
+ * @param String $value The token's value
965
+ *
966
+ * @return String HTML code of the highlighted token.
967
+ */
968
+ protected static function highlightNumber($value)
969
+ {
970
+ if (self::is_cli()) {
971
+ return self::$cli_number . $value . "\x1b[0m";
972
+ } else {
973
+ return '<span ' . self::$number_attributes . '>' . $value . '</span>';
974
+ }
975
+ }
976
+
977
+ /**
978
+ * Highlights an error
979
+ *
980
+ * @param String $value The token's value
981
+ *
982
+ * @return String HTML code of the highlighted token.
983
+ */
984
+ protected static function highlightError($value)
985
+ {
986
+ if (self::is_cli()) {
987
+ return self::$cli_error . $value . "\x1b[0m";
988
+ } else {
989
+ return '<span ' . self::$error_attributes . '>' . $value . '</span>';
990
+ }
991
+ }
992
+
993
+ /**
994
+ * Highlights a comment
995
+ *
996
+ * @param String $value The token's value
997
+ *
998
+ * @return String HTML code of the highlighted token.
999
+ */
1000
+ protected static function highlightComment($value)
1001
+ {
1002
+ if (self::is_cli()) {
1003
+ return self::$cli_comment . $value . "\x1b[0m";
1004
+ } else {
1005
+ return '<span ' . self::$comment_attributes . '>' . $value . '</span>';
1006
+ }
1007
+ }
1008
+
1009
+ /**
1010
+ * Highlights a word token
1011
+ *
1012
+ * @param String $value The token's value
1013
+ *
1014
+ * @return String HTML code of the highlighted token.
1015
+ */
1016
+ protected static function highlightWord($value)
1017
+ {
1018
+ if (self::is_cli()) {
1019
+ return self::$cli_word . $value . "\x1b[0m";
1020
+ } else {
1021
+ return '<span ' . self::$word_attributes . '>' . $value . '</span>';
1022
+ }
1023
+ }
1024
+
1025
+ /**
1026
+ * Highlights a variable token
1027
+ *
1028
+ * @param String $value The token's value
1029
+ *
1030
+ * @return String HTML code of the highlighted token.
1031
+ */
1032
+ protected static function highlightVariable($value)
1033
+ {
1034
+ if (self::is_cli()) {
1035
+ return self::$cli_variable . $value . "\x1b[0m";
1036
+ } else {
1037
+ return '<span ' . self::$variable_attributes . '>' . $value . '</span>';
1038
+ }
1039
+ }
1040
+
1041
+ /**
1042
+ * Helper function for building regular expressions for reserved words and boundary characters
1043
+ *
1044
+ * @param String $a The string to be quoted
1045
+ *
1046
+ * @return String The quoted string
1047
+ */
1048
+ private static function quote_regex($a)
1049
+ {
1050
+ return preg_quote($a,'/');
1051
+ }
1052
+
1053
+ /**
1054
+ * Helper function for building string output
1055
+ *
1056
+ * @param String $string The string to be quoted
1057
+ *
1058
+ * @return String The quoted string
1059
+ */
1060
+ private static function output($string)
1061
+ {
1062
+ if (self::is_cli()) {
1063
+ return $string."\n";
1064
+ } else {
1065
+ $string=trim($string);
1066
+ if (!self::$use_pre) {
1067
+ return $string;
1068
+ }
1069
+
1070
+ return '<pre '.self::$pre_attributes.'>' . $string . '</pre>';
1071
+ }
1072
+ }
1073
+
1074
+ private static function is_cli()
1075
+ {
1076
+ if (isset(self::$cli)) return self::$cli;
1077
+ else return php_sapi_name() === 'cli';
1078
+ }
1079
+
1080
+ }
package.xml CHANGED
@@ -2,7 +2,7 @@
2
  <root>
3
  <name>Ecocode_Profiler</name>
4
  <channel>community</channel>
5
- <version>1.1.0</version>
6
  <description>&lt;h1 id="ecocode-profiler-magento-1-x-web-profiler"&gt;ecocode Profiler - Magento 1.x Web Profiler&lt;/h1&gt;
7
  &lt;p&gt;&lt;a href="https://travis-ci.org/ecoco/magento_profiler"&gt;&lt;img src="https://travis-ci.org/ecoco/magento_profiler.svg?branch=master" alt="Build Status"&gt;&lt;/a&gt;
8
  &lt;a href="https://coveralls.io/github/ecoco/magento_profiler?branch=master"&gt;&lt;img src="https://coveralls.io/repos/github/ecoco/magento_profiler/badge.svg?branch=master" alt="Coverage Status"&gt;&lt;/a&gt;
@@ -26,7 +26,7 @@ The concept and code of the WebProfiler have been ported to assist with Magento
26
  &lt;/ul&gt;
27
  &lt;hr&gt;
28
  &lt;p&gt;&lt;img src="https://github.com/ecoco/magento_profiler/raw/v1.1.0/docs/image/toolbar.jpg" alt="Toolbar" title="Toolbar"&gt;&lt;/p&gt;
29
- &lt;p&gt;&lt;img src="/docs/image/profiler.jpg" alt="Profiler" title="Profiler"&gt;&lt;/p&gt;
30
  &lt;p&gt;&lt;a href="docs/images.md"&gt;More Images&lt;/a&gt;&lt;/p&gt;
31
  &lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
32
  &lt;h3 id="composer-recommended-"&gt;Composer (recommended)&lt;/h3&gt;
@@ -166,12 +166,12 @@ nginx config&lt;/p&gt;
166
  &lt;li&gt;&lt;a href="https://github.com/symfony/web-profiler-bundle"&gt;Symfony WebProfiler&lt;/a&gt;&lt;/li&gt;
167
  &lt;/ul&gt;
168
  </description>
169
- <summery>Web Profiler for Magento 1.x</summery>
170
  <license>MIT</license>
171
  <stability>stable</stability>
172
  <notes/>
173
- <date>2016-10-11</date>
174
- <time>19:23:09</time>
175
  <authors>
176
  <author>
177
  <name>Justus Krapp</name>
@@ -204,16 +204,10 @@ nginx config&lt;/p&gt;
204
  <dir name="base">
205
  <dir name="default">
206
  <dir name="layout">
207
- <file name="ecocode_profiler.xml" hash="77c53c870841abec7e9b991d3d13be23"/>
208
  </dir>
209
  <dir name="template">
210
  <dir name="ecocode_profiler">
211
- <file name="back-trace.phtml" hash="3e87214048db56081377577284b0ed92"/>
212
- <file name="bag.phtml" hash="bd4363dfe3f58bb352cd2f7aecc220a0"/>
213
- <file name="layout.phtml" hash="4b7a285bcf3811a63089f23de5f7bb2a"/>
214
- <file name="toolbar_js.phtml" hash="4c55d25dba7c8528fc12fb132cf95670"/>
215
- <file name="toolbar.css.phtml" hash="e69c6cab4024a1c92859bd6d9a5c90bc"/>
216
- <file name="toolbar.phtml" hash="8fcffc1866e836ddd02939c67b75cc26"/>
217
  <dir name="collector">
218
  <dir name="ajax">
219
  <file name="toolbar.phtml" hash="82f3f425377c110b2b2931c0a2021b5e"/>
@@ -224,7 +218,7 @@ nginx config&lt;/p&gt;
224
  <dir name="cache">
225
  <file name="menu.phtml" hash="7c84720f0d33760a719d1700fb4aeb90"/>
226
  <file name="panel.phtml" hash="4ec12213e351cf5b8ef33710abeee8eb"/>
227
- <file name="toolbar.phtml" hash="ef01eabfdee95829d4f4a6e71daac816"/>
228
  </dir>
229
  <dir name="config">
230
  <file name="menu.phtml" hash="3413b99ba04b314a14c1ee3394ea0cde"/>
@@ -248,7 +242,7 @@ nginx config&lt;/p&gt;
248
  <file name="panel.phtml" hash="c1580c5591d9ed1e7508223e0440139e"/>
249
  <file name="toolbar.phtml" hash="f9f4c1aa7eb6e2b4c5f9fb29c4355c3b"/>
250
  <dir name="panel">
251
- <file name="log-table.phtml" hash="0d305d9cecc0f8cd2daa559577f22e59"/>
252
  </dir>
253
  </dir>
254
  <dir name="memory">
@@ -256,21 +250,24 @@ nginx config&lt;/p&gt;
256
  </dir>
257
  <dir name="model">
258
  <file name="menu.phtml" hash="00a2226bc05b0fef429160ecafd60204"/>
259
- <file name="panel.phtml" hash="fb85a775faea43e0fddc3e71179e8310"/>
260
  <file name="toolbar.phtml" hash="cbd77333b03d1ade489c249346b4e5fe"/>
261
  </dir>
262
  <dir name="mysql">
263
- <file name="menu.phtml" hash="e9ff757f0330116f232961470ab63ffe"/>
264
- <file name="panel.phtml" hash="c291f1492478fe99ffd90efc974d041d"/>
265
  <file name="toolbar.phtml" hash="166394a1bef92a73f3a9c60b35249eb9"/>
266
  <dir name="panel">
267
- <file name="query-table.phtml" hash="68d4a6d2206477ef1d4ecca49ceda721"/>
268
  </dir>
269
  </dir>
270
  <dir name="request">
271
  <file name="menu.phtml" hash="45de32145ba7d367dd400ffdfb726295"/>
272
- <file name="panel.phtml" hash="2b4543345ad9ab659d165f71b0837539"/>
273
- <file name="toolbar.phtml" hash="d31ee40313be5c70d844bf85204432d4"/>
 
 
 
274
  </dir>
275
  <dir name="rewrite">
276
  <file name="menu.phtml" hash="881118b3135e5a2f15e2cb8072b0c2ed"/>
@@ -285,7 +282,7 @@ nginx config&lt;/p&gt;
285
  <file name="panel.phtml" hash="1eef90a79983a141c1db14ca0bcd2afb"/>
286
  <file name="toolbar.phtml" hash="12702548344ed6a63487394201f0eb56"/>
287
  <dir name="panel">
288
- <file name="table.phtml" hash="e0f080dbe249cede69b8f566dd7be82c"/>
289
  </dir>
290
  </dir>
291
  </dir>
@@ -296,17 +293,24 @@ nginx config&lt;/p&gt;
296
  </dir>
297
  </dir>
298
  <dir name="profiler">
299
- <file name="base.css.phtml" hash="5aa4306149ccb84867915bce7e4a5f12"/>
300
  <file name="base.js.phtml" hash="dc8fdc11af0a8458aceee4766e337620"/>
301
- <file name="summery.phtml" hash="9a71359e8e47ded85f55299aed93371e"/>
302
  <dir name="search">
303
  <file name="results.phtml" hash="970d81fff56177afcc882f8efb467f7e"/>
304
  <file name="summery.phtml" hash="7d3e70179beef079a5efde9fea6dd504"/>
305
  </dir>
306
  </dir>
307
  <dir name="renderer">
308
- <file name="context.phtml" hash="38f3f9e0b17f96eb6e01332e78337f55"/>
 
 
 
309
  </dir>
 
 
 
 
310
  </dir>
311
  </dir>
312
  </dir>
@@ -316,22 +320,23 @@ nginx config&lt;/p&gt;
316
  <target name="magecommunity">
317
  <dir name="Ecocode">
318
  <dir name="Profiler">
319
- <file name="autoloader.php" hash="625350c21fc1ce3b298e5cef41198308"/>
320
- <file name="debug.php" hash="f5b9e0a679f16a948f540b2e7fa6c25b"/>
321
  <dir name="Block">
322
- <file name="Bag.php" hash="6f574bbd70410b7cc4198c88131ab9fd"/>
323
- <file name="Toolbar.php" hash="f1a247c7cc273598d80d0b3c69263536"/>
324
  <dir name="Collector">
325
- <file name="Base.php" hash="8f6852999389c3e6159c93a8dc21a3a7"/>
326
  <file name="Menu.php" hash="be064554e1868ef0d06d0a9393fbe460"/>
327
  <dir name="Layout">
328
- <file name="Panel.php" hash="a3250d15e46573d07e6be930bff09bbc"/>
329
  </dir>
330
  <dir name="Log">
331
  <file name="Panel.php" hash="7836cb8d57f778765c433e1887908aac"/>
332
  </dir>
333
  <dir name="Mysql">
334
- <file name="Panel.php" hash="95c41d688e01ab371a8b74a207342e07"/>
 
 
 
335
  </dir>
336
  <dir name="Translation">
337
  <file name="Panel.php" hash="f3da35eb4848ad9bc8baa99f89ae6748"/>
@@ -344,24 +349,30 @@ nginx config&lt;/p&gt;
344
  </dir>
345
  </dir>
346
  <dir name="Renderer">
347
- <file name="AbstractRenderer.php" hash="451a64191ddd17741195511b357179f0"/>
348
- <file name="BackTrace.php" hash="7bf2d900481bed0c5a06613ab687b7ef"/>
 
349
  <file name="Context.php" hash="d570e34a9565e3cad0781ee354bd4ef9"/>
350
  <file name="RendererInterface.php" hash="a34a484b2c7859696c214ade11208b04"/>
 
351
  <dir name="Log">
352
- <file name="LogTable.php" hash="ace6bc645cbbcd0f5fb4cfd9b08e6859"/>
353
  </dir>
354
  <dir name="Mysql">
355
  <file name="QueryTable.php" hash="38a9b601e5f1379285d07e4361d94ac1"/>
356
  </dir>
 
 
 
357
  </dir>
 
358
  </dir>
359
  <dir name="Controller">
360
  <file name="AbstractController.php" hash="df479a9daa699be75d49930cc7468648"/>
361
  </dir>
362
  <dir name="controllers">
363
  <file name="CacheController.php" hash="cba1eefa1c5b487abbd44eaa6167900b"/>
364
- <file name="IndexController.php" hash="263e2bf4631e037fb61a5d1f131cb555"/>
365
  </dir>
366
  <dir name="Db">
367
  <dir name="Statement">
@@ -371,47 +382,49 @@ nginx config&lt;/p&gt;
371
  </dir>
372
  </dir>
373
  <dir name="etc">
374
- <file name="config.xml" hash="3e655889fd41aa91071c68fa0b63d93e"/>
375
- <file name="development.xml" hash="569481da5b5fc6a17e0f69747ddb41be"/>
376
  </dir>
377
  <dir name="Helper">
378
  <file name="AbstractHelper.php" hash="f3b8fc47c99b7a9f492c09ee38d2a4dd"/>
379
- <file name="Code.php" hash="5cd26ca017a787618fdf552e48ac0f72"/>
380
  <file name="Context.php" hash="c8d0d66a13a558b26092fbe375643819"/>
381
- <file name="Data.php" hash="d2a72158860ba97e4c493bec643e2bed"/>
382
- <file name="Renderer.php" hash="5129f2242f9456cb72cd10fb205531af"/>
383
  <file name="Rewrite.php" hash="5d14a5cade6df7fe4f0fdb14b381d21c"/>
384
- <file name="Sql.php" hash="2daba313727d3376f63f5096f4c67532"/>
385
- <file name="ValueExporter.php" hash="d5c47a798bf0bc63e22ac8e530c97513"/>
386
  </dir>
387
  <dir name="Model">
388
- <file name="AppDev.php" hash="3452f2a7476bda585f2e117fe6b2007f"/>
389
- <file name="Context.php" hash="6f88c38762b1cea9b61dceffa28d4bfe"/>
390
  <file name="ContextInterface.php" hash="6fa0b665a1f66469072c7a15064241fe"/>
391
- <file name="DebugLoggerInterface.php" hash="fb77da964513216bced10423f9e9ef79"/>
392
- <file name="Logger.php" hash="6b7a41a4b32d61c757291f4611bcb065"/>
393
- <file name="Observer.php" hash="d470dd34415b67c1d210322cafbe6b52"/>
394
- <file name="Profile.php" hash="b109854a402cb400d689939db515a8f7"/>
395
- <file name="Profiler.php" hash="d656aa79765761d6af7d41c0692db62c"/>
 
 
396
  <dir name="Collector">
397
- <file name="AbstractDataCollector.php" hash="7a58e7a7f781fcb25596ec454a0941fa"/>
398
  <file name="AjaxDataCollector.php" hash="8abe36cbc71801d9509a1607cb510872"/>
399
  <file name="CacheDataCollector.php" hash="121234aaeff67cfb7e367f4d0ea6ca74"/>
400
- <file name="ConfigDataCollector.php" hash="2717afc87c5c67af0b09219c14ebb10f"/>
401
  <file name="ContextDataCollector.php" hash="ea8e04938af2e1ec2a095306d8c0a07d"/>
402
  <file name="CustomerDataCollector.php" hash="b49edceafe5c60a2ffb96dc3c62b4a82"/>
403
  <file name="DataCollectorInterface.php" hash="33082cfb75eedf75b6af2c6afac3d782"/>
404
  <file name="EventDataCollector.php" hash="b54c69b72dd4694c33a8934c4588aa14"/>
405
  <file name="LateDataCollectorInterface.php" hash="11f0136ac985fbadde129c2de7082df1"/>
406
- <file name="LayoutDataCollector.php" hash="a0161acecfe24eae72f1a23055d8dd31"/>
407
  <file name="LogDataCollector.php" hash="ed5554e57957606f11debbf4f5d3b6a9"/>
408
  <file name="MemoryDataCollector.php" hash="6b9df2616c98fb717fe987650b05e839"/>
409
- <file name="ModelDataCollector.php" hash="1942b69c4b7e205e85a03f400f25e357"/>
410
  <file name="MysqlDataCollector.php" hash="6b22fb7c698632f38516ae67f5e72e3e"/>
411
- <file name="RequestDataCollector.php" hash="2a7c8fcea477da650c6fde974fdddd54"/>
412
  <file name="RewriteDataCollector.php" hash="94c7822840a6a8e56662df45c3c05a13"/>
413
  <file name="TimeDataCollector.php" hash="9ba56d95b0cdf1b736ec09c101bcc17a"/>
414
- <file name="TranslationDataCollector.php" hash="f2dbb421aded73ecad1d28288c0852f2"/>
415
  </dir>
416
  <dir name="Core">
417
  <file name="Cache.php" hash="4d5153b5ef8d3f32b01a20b6f33a694c"/>
@@ -423,26 +436,30 @@ nginx config&lt;/p&gt;
423
  <file name="ResponseHeaderBag.php" hash="d27b8d35c3a4fc7ff050f5971ffea835"/>
424
  </dir>
425
  <dir name="Logger">
426
- <file name="DebugHandler.php" hash="2e64a8afb1f054668992ab9026155988"/>
 
427
  </dir>
428
  <dir name="Observer">
429
- <file name="Context.php" hash="46486a8e8d854dc8c022addae27eb713"/>
430
  </dir>
431
  <dir name="Profiler">
432
- <file name="FileStorage.php" hash="0f7b9b499d7d0ef070db55d00608d086"/>
433
  <file name="StorageInterface.php" hash="fe90e695474f4354bd6481d904c6c56c"/>
434
  </dir>
435
  </dir>
436
  <dir name="overwrite">
437
- <file name="Mage.php" hash="6141bb3e6e7e307d37e4bc9d92a409da"/>
438
  <file name="MageCoreModelResource.php" hash="f800cbedca91b1ffbd522b7e2e9262ca"/>
439
  <file name="MageCoreModelResourceDbAbstract.php" hash="1cac148b8666cf267f8d3cfeca80a114"/>
440
- <file name="MageCoreModelStore.php" hash="8b254445c375ecba32f02eb67566b759"/>
441
- <file name="MageCoreModelTranslate.php" hash="981b052d60c99afbfce2499d624438de"/>
442
  <file name="MageEavModelEntityAbstract.php" hash="2f8f6ed49f554d0eb68a6ccf83464a5b"/>
443
  </dir>
444
  </dir>
445
  </dir>
446
  </target>
 
 
 
447
  </contents>
448
- </root>
2
  <root>
3
  <name>Ecocode_Profiler</name>
4
  <channel>community</channel>
5
+ <version>1.2.0</version>
6
  <description>&lt;h1 id="ecocode-profiler-magento-1-x-web-profiler"&gt;ecocode Profiler - Magento 1.x Web Profiler&lt;/h1&gt;
7
  &lt;p&gt;&lt;a href="https://travis-ci.org/ecoco/magento_profiler"&gt;&lt;img src="https://travis-ci.org/ecoco/magento_profiler.svg?branch=master" alt="Build Status"&gt;&lt;/a&gt;
8
  &lt;a href="https://coveralls.io/github/ecoco/magento_profiler?branch=master"&gt;&lt;img src="https://coveralls.io/repos/github/ecoco/magento_profiler/badge.svg?branch=master" alt="Coverage Status"&gt;&lt;/a&gt;
26
  &lt;/ul&gt;
27
  &lt;hr&gt;
28
  &lt;p&gt;&lt;img src="https://github.com/ecoco/magento_profiler/raw/v1.1.0/docs/image/toolbar.jpg" alt="Toolbar" title="Toolbar"&gt;&lt;/p&gt;
29
+ &lt;p&gt;&lt;img src="https://github.com/ecoco/magento_profiler/raw/v1.1.0/docs/image/profiler.jpg" alt="Profiler" title="Profiler"&gt;&lt;/p&gt;
30
  &lt;p&gt;&lt;a href="docs/images.md"&gt;More Images&lt;/a&gt;&lt;/p&gt;
31
  &lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
32
  &lt;h3 id="composer-recommended-"&gt;Composer (recommended)&lt;/h3&gt;
166
  &lt;li&gt;&lt;a href="https://github.com/symfony/web-profiler-bundle"&gt;Symfony WebProfiler&lt;/a&gt;&lt;/li&gt;
167
  &lt;/ul&gt;
168
  </description>
169
+ <summary>Web Profiler for Magento 1.x</summary>
170
  <license>MIT</license>
171
  <stability>stable</stability>
172
  <notes/>
173
+ <date>2016-10-19</date>
174
+ <time>13:03:36</time>
175
  <authors>
176
  <author>
177
  <name>Justus Krapp</name>
204
  <dir name="base">
205
  <dir name="default">
206
  <dir name="layout">
207
+ <file name="ecocode_profiler.xml" hash="b5da16729622d244ddf1d6e885d86f3a"/>
208
  </dir>
209
  <dir name="template">
210
  <dir name="ecocode_profiler">
 
 
 
 
 
 
211
  <dir name="collector">
212
  <dir name="ajax">
213
  <file name="toolbar.phtml" hash="82f3f425377c110b2b2931c0a2021b5e"/>
218
  <dir name="cache">
219
  <file name="menu.phtml" hash="7c84720f0d33760a719d1700fb4aeb90"/>
220
  <file name="panel.phtml" hash="4ec12213e351cf5b8ef33710abeee8eb"/>
221
+ <file name="toolbar.phtml" hash="ffd9ccf2313dee1cc874596a535d4135"/>
222
  </dir>
223
  <dir name="config">
224
  <file name="menu.phtml" hash="3413b99ba04b314a14c1ee3394ea0cde"/>
242
  <file name="panel.phtml" hash="c1580c5591d9ed1e7508223e0440139e"/>
243
  <file name="toolbar.phtml" hash="f9f4c1aa7eb6e2b4c5f9fb29c4355c3b"/>
244
  <dir name="panel">
245
+ <file name="log-table.phtml" hash="e4cfab2b0c96318fef683f78898c7ccc"/>
246
  </dir>
247
  </dir>
248
  <dir name="memory">
250
  </dir>
251
  <dir name="model">
252
  <file name="menu.phtml" hash="00a2226bc05b0fef429160ecafd60204"/>
253
+ <file name="panel.phtml" hash="152f1fc963b64f744e8159deaf4a8b5c"/>
254
  <file name="toolbar.phtml" hash="cbd77333b03d1ade489c249346b4e5fe"/>
255
  </dir>
256
  <dir name="mysql">
257
+ <file name="menu.phtml" hash="6574552d5af1354947dd63579966f1ef"/>
258
+ <file name="panel.phtml" hash="c3400e82754e1a9dd2cdf7134acbc384"/>
259
  <file name="toolbar.phtml" hash="166394a1bef92a73f3a9c60b35249eb9"/>
260
  <dir name="panel">
261
+ <file name="query-table.phtml" hash="8d23dce7ce3160f6a1b8a1d7fbdad4a8"/>
262
  </dir>
263
  </dir>
264
  <dir name="request">
265
  <file name="menu.phtml" hash="45de32145ba7d367dd400ffdfb726295"/>
266
+ <file name="panel.phtml" hash="4d076b410586ac7ade04c672cb5c46c6"/>
267
+ <file name="toolbar.phtml" hash="401a608fb75bebcbd1cbdf336c033838"/>
268
+ <dir name="toolbar">
269
+ <file name="handler.phtml" hash="8bf3a498fb2d4cd0423be095be193db5"/>
270
+ </dir>
271
  </dir>
272
  <dir name="rewrite">
273
  <file name="menu.phtml" hash="881118b3135e5a2f15e2cb8072b0c2ed"/>
282
  <file name="panel.phtml" hash="1eef90a79983a141c1db14ca0bcd2afb"/>
283
  <file name="toolbar.phtml" hash="12702548344ed6a63487394201f0eb56"/>
284
  <dir name="panel">
285
+ <file name="table.phtml" hash="0da6fb9967dbd157e277b7a922dc913f"/>
286
  </dir>
287
  </dir>
288
  </dir>
293
  </dir>
294
  </dir>
295
  <dir name="profiler">
296
+ <file name="base.css.phtml" hash="50868e27ca6e15f0871de0480b383851"/>
297
  <file name="base.js.phtml" hash="dc8fdc11af0a8458aceee4766e337620"/>
298
+ <file name="summery.phtml" hash="6e820500d76017d6e504cee4453191cb"/>
299
  <dir name="search">
300
  <file name="results.phtml" hash="970d81fff56177afcc882f8efb467f7e"/>
301
  <file name="summery.phtml" hash="7d3e70179beef079a5efde9fea6dd504"/>
302
  </dir>
303
  </dir>
304
  <dir name="renderer">
305
+ <file name="bag.phtml" hash="71f989e10d23a657bd7c533ff4449c6a"/>
306
+ <file name="call-stack.phtml" hash="2b239a6c3f8423be2b3fb950c4180dba"/>
307
+ <file name="context.phtml" hash="32e77b1d1fa23ead577fae3d70ff4b62"/>
308
+ <file name="table.phtml" hash="faa3d12ffe1b125a1a41d92f4ddf1310"/>
309
  </dir>
310
+ <file name="layout.phtml" hash="8fc45406e12d811f30fc577ef8f2d911"/>
311
+ <file name="toolbar_js.phtml" hash="d00323459ef6e5099739b150cee9ea01"/>
312
+ <file name="toolbar.css.phtml" hash="e69c6cab4024a1c92859bd6d9a5c90bc"/>
313
+ <file name="toolbar.phtml" hash="8fcffc1866e836ddd02939c67b75cc26"/>
314
  </dir>
315
  </dir>
316
  </dir>
320
  <target name="magecommunity">
321
  <dir name="Ecocode">
322
  <dir name="Profiler">
323
+ <file name="autoloader.php" hash="4b9869094f4efcaab59cc143565d902e"/>
324
+ <file name="debug.php" hash="cc76ccaa500dee58a07a80ad9c6b260c"/>
325
  <dir name="Block">
 
 
326
  <dir name="Collector">
327
+ <file name="Base.php" hash="a0048075f2194c3601da2405309e1393"/>
328
  <file name="Menu.php" hash="be064554e1868ef0d06d0a9393fbe460"/>
329
  <dir name="Layout">
330
+ <file name="Panel.php" hash="2de5d0fcb4e801844d0555a4112f8122"/>
331
  </dir>
332
  <dir name="Log">
333
  <file name="Panel.php" hash="7836cb8d57f778765c433e1887908aac"/>
334
  </dir>
335
  <dir name="Mysql">
336
+ <file name="Panel.php" hash="bd27db5270af5d74a67bded11d9026b3"/>
337
+ </dir>
338
+ <dir name="Request">
339
+ <file name="Toolbar.php" hash="6926ed38ee5720a4164bc3819056ed3e"/>
340
  </dir>
341
  <dir name="Translation">
342
  <file name="Panel.php" hash="f3da35eb4848ad9bc8baa99f89ae6748"/>
349
  </dir>
350
  </dir>
351
  <dir name="Renderer">
352
+ <file name="AbstractRenderer.php" hash="0c280a33220e1cc55c9f9238499feac5"/>
353
+ <file name="Bag.php" hash="bf286a4897097c6ee3891b5b000c4343"/>
354
+ <file name="CallStack.php" hash="e607a88467d171eca2df47120094f691"/>
355
  <file name="Context.php" hash="d570e34a9565e3cad0781ee354bd4ef9"/>
356
  <file name="RendererInterface.php" hash="a34a484b2c7859696c214ade11208b04"/>
357
+ <file name="Table.php" hash="10eb3d85b25f98661731412caf89435f"/>
358
  <dir name="Log">
359
+ <file name="LogTable.php" hash="57b20710798261e8a277233ddf4aa661"/>
360
  </dir>
361
  <dir name="Mysql">
362
  <file name="QueryTable.php" hash="38a9b601e5f1379285d07e4361d94ac1"/>
363
  </dir>
364
+ <dir name="Request">
365
+ <file name="ToolbarHandler.php" hash="462475f0c5af6ee1674523fa95b8332d"/>
366
+ </dir>
367
  </dir>
368
+ <file name="Toolbar.php" hash="06c0401453a13ae45bb14e5ee26341e7"/>
369
  </dir>
370
  <dir name="Controller">
371
  <file name="AbstractController.php" hash="df479a9daa699be75d49930cc7468648"/>
372
  </dir>
373
  <dir name="controllers">
374
  <file name="CacheController.php" hash="cba1eefa1c5b487abbd44eaa6167900b"/>
375
+ <file name="IndexController.php" hash="088b32d8d6616d7027e18aed2177eb4b"/>
376
  </dir>
377
  <dir name="Db">
378
  <dir name="Statement">
382
  </dir>
383
  </dir>
384
  <dir name="etc">
385
+ <file name="config.xml" hash="8003393b0794d688b33577d1d0e7def7"/>
386
+ <file name="development.xml" hash="5ca041f2c3683c795131c17276824e0a"/>
387
  </dir>
388
  <dir name="Helper">
389
  <file name="AbstractHelper.php" hash="f3b8fc47c99b7a9f492c09ee38d2a4dd"/>
390
+ <file name="Code.php" hash="9325a909db6d4e4c00215410d8d32937"/>
391
  <file name="Context.php" hash="c8d0d66a13a558b26092fbe375643819"/>
392
+ <file name="Data.php" hash="01c91a5ce354645b89ffb9f7edec2681"/>
393
+ <file name="Renderer.php" hash="4e1bc69441cc7bb0a5be7b640908ff6d"/>
394
  <file name="Rewrite.php" hash="5d14a5cade6df7fe4f0fdb14b381d21c"/>
395
+ <file name="Sql.php" hash="dac8ad2ec5dd2419811c65abb60b8dc7"/>
396
+ <file name="ValueExporter.php" hash="42a51d69104617aeccc11acf86e862e9"/>
397
  </dir>
398
  <dir name="Model">
399
+ <file name="AppDev.php" hash="94e08efbb73221da5754beae621765d4"/>
400
+ <file name="Context.php" hash="e5bb05467e056a4538e4c4971efcc24d"/>
401
  <file name="ContextInterface.php" hash="6fa0b665a1f66469072c7a15064241fe"/>
402
+ <file name="Logger.php" hash="681b14bec2fe35284949d846307183a1"/>
403
+ <file name="LoggerInterface.php" hash="12fc1e5b210170d554387855babda960"/>
404
+ <file name="NullLogger.php" hash="2dd2abc704544069b24dde5b02a1c4a1"/>
405
+ <file name="Observer.php" hash="fb9c87531fda6fe2cefdbc0c36a9ed67"/>
406
+ <file name="Profile.php" hash="a4e56a719cbf9ef991c921f4baefc9ee"/>
407
+ <file name="Profiler.php" hash="f6d638fd55de32b64df81dacecbb783e"/>
408
+ <file name="Session.php" hash="98f2fdfbeb3ccabf6bd0c05870d568dc"/>
409
  <dir name="Collector">
410
+ <file name="AbstractDataCollector.php" hash="770cc563fa01b3e2a2298dca54deed62"/>
411
  <file name="AjaxDataCollector.php" hash="8abe36cbc71801d9509a1607cb510872"/>
412
  <file name="CacheDataCollector.php" hash="121234aaeff67cfb7e367f4d0ea6ca74"/>
413
+ <file name="ConfigDataCollector.php" hash="9d799af590c67326efb708299a5adf1d"/>
414
  <file name="ContextDataCollector.php" hash="ea8e04938af2e1ec2a095306d8c0a07d"/>
415
  <file name="CustomerDataCollector.php" hash="b49edceafe5c60a2ffb96dc3c62b4a82"/>
416
  <file name="DataCollectorInterface.php" hash="33082cfb75eedf75b6af2c6afac3d782"/>
417
  <file name="EventDataCollector.php" hash="b54c69b72dd4694c33a8934c4588aa14"/>
418
  <file name="LateDataCollectorInterface.php" hash="11f0136ac985fbadde129c2de7082df1"/>
419
+ <file name="LayoutDataCollector.php" hash="2a84dd0fa9d871ce903d3147b9f2bab3"/>
420
  <file name="LogDataCollector.php" hash="ed5554e57957606f11debbf4f5d3b6a9"/>
421
  <file name="MemoryDataCollector.php" hash="6b9df2616c98fb717fe987650b05e839"/>
422
+ <file name="ModelDataCollector.php" hash="f234954b4b88992bf50b818b00cb4446"/>
423
  <file name="MysqlDataCollector.php" hash="6b22fb7c698632f38516ae67f5e72e3e"/>
424
+ <file name="RequestDataCollector.php" hash="86e74b6db9948cc687424a638c408863"/>
425
  <file name="RewriteDataCollector.php" hash="94c7822840a6a8e56662df45c3c05a13"/>
426
  <file name="TimeDataCollector.php" hash="9ba56d95b0cdf1b736ec09c101bcc17a"/>
427
+ <file name="TranslationDataCollector.php" hash="7c061c064ba95604b89c9b5e01d00923"/>
428
  </dir>
429
  <dir name="Core">
430
  <file name="Cache.php" hash="4d5153b5ef8d3f32b01a20b6f33a694c"/>
436
  <file name="ResponseHeaderBag.php" hash="d27b8d35c3a4fc7ff050f5971ffea835"/>
437
  </dir>
438
  <dir name="Logger">
439
+ <file name="DebugHandler.php" hash="d107142dc578dd4bb068ee81a959cb10"/>
440
+ <file name="DebugHandlerInterface.php" hash="d7ad84fb6fc5794be558abf0ad9f8803"/>
441
  </dir>
442
  <dir name="Observer">
443
+ <file name="Context.php" hash="a48925aacf4a875899a0b6e42ff91b7d"/>
444
  </dir>
445
  <dir name="Profiler">
446
+ <file name="FileStorage.php" hash="bfe9fb9ddd17d5818fc0fb1d1b154ba8"/>
447
  <file name="StorageInterface.php" hash="fe90e695474f4354bd6481d904c6c56c"/>
448
  </dir>
449
  </dir>
450
  <dir name="overwrite">
451
+ <file name="Mage.php" hash="886a54281b80d314398aa193d6a2970e"/>
452
  <file name="MageCoreModelResource.php" hash="f800cbedca91b1ffbd522b7e2e9262ca"/>
453
  <file name="MageCoreModelResourceDbAbstract.php" hash="1cac148b8666cf267f8d3cfeca80a114"/>
454
+ <file name="MageCoreModelStore.php" hash="18103f46ad50dd13e79b006bd7180b06"/>
455
+ <file name="MageCoreModelTranslate.php" hash="d8a97ad69d13c66ca1825c79f86620b3"/>
456
  <file name="MageEavModelEntityAbstract.php" hash="2f8f6ed49f554d0eb68a6ccf83464a5b"/>
457
  </dir>
458
  </dir>
459
  </dir>
460
  </target>
461
+ <target name="magelib">
462
+ <file name="SqlFormatter.php" hash="679860fbd8cff0716ab1e86e62c96684"/>
463
+ </target>
464
  </contents>
465
+ </root>