Skip to content

Commit 507bb11

Browse files
committed
Added plugin names
1 parent 96bf3a1 commit 507bb11

File tree

5 files changed

+91
-8
lines changed

5 files changed

+91
-8
lines changed

Collector/DebugPluginCollector.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ class DebugPluginCollector extends DataCollector
2121
*/
2222
private $formatter;
2323

24+
/**
25+
* @var PluginJournal
26+
*/
27+
private $journal;
28+
2429
/**
2530
* @param Formatter $formatter
2631
*/
27-
public function __construct(Formatter $formatter = null)
32+
public function __construct(Formatter $formatter, PluginJournal $journal)
2833
{
29-
$this->formatter = $formatter ?: new SimpleFormatter();
34+
$this->formatter = $formatter;
35+
$this->journal = $journal;
3036
}
3137

3238
/**
@@ -116,6 +122,14 @@ public function getClients()
116122
return ClientDataCollector::createFromCollectedData($this->data);
117123
}
118124

125+
/**
126+
* @return PluginJournal
127+
*/
128+
public function getJournal()
129+
{
130+
return $this->journal;
131+
}
132+
119133
/**
120134
* {@inheritdoc}
121135
*/
@@ -131,4 +145,14 @@ public function getName()
131145
{
132146
return 'httplug';
133147
}
148+
149+
public function serialize()
150+
{
151+
return serialize([$this->data, $this->journal]);
152+
}
153+
154+
public function unserialize($data)
155+
{
156+
list($this->data, $this->journal) = unserialize($data);
157+
}
134158
}

Collector/PluginJournal.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Http\HttplugBundle\Collector;
4+
5+
/**
6+
* A object that remembers what plugins are configured for which clients.
7+
*
8+
* @author Tobias Nyholm <[email protected]>
9+
*/
10+
class PluginJournal
11+
{
12+
/**
13+
* @var array ['clientName'=>['index' => 'PluginName']
14+
*/
15+
private $data;
16+
17+
/**
18+
* @return array
19+
*/
20+
public function getPlugins($clientName)
21+
{
22+
return $this->data[$clientName];
23+
}
24+
25+
/**
26+
* @return string|null
27+
*/
28+
public function getPluginName($clientName, $idx)
29+
{
30+
if (isset($this->data[$clientName][$idx])) {
31+
return $this->data[$clientName][$idx];
32+
}
33+
34+
return;
35+
}
36+
37+
/**
38+
* @param string $clientName
39+
* @param array $plugins
40+
*
41+
* @return $this
42+
*/
43+
public function setPlugins($clientName, array $plugins)
44+
{
45+
$this->data[$clientName] = $plugins;
46+
47+
return $this;
48+
}
49+
50+
}

DependencyInjection/HttplugExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ function ($id) {
226226
->addArgument(new Reference($arguments['factory']))
227227
->addArgument($arguments['config'])
228228
->addArgument(['debug_plugins'=>[new Reference($serviceIdDebugPlugin)]]);
229+
230+
// tell the plugin journal what plugins we used
231+
$container->getDefinition('httplug.collector.plugin_journal')
232+
->addMethodCall('setPlugins', [$name, $arguments['plugins']]);
229233
}
230234

231235

Resources/config/data-collector.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
55

66
<services>
7+
<service id="httplug.collector.plugin_journal" class="Http\HttplugBundle\Collector\PluginJournal" public="false" />
78
<service id="httplug.formatter.full_http_message" class="Http\Message\Formatter\FullHttpMessageFormatter" public="false" />
89

910
<service id="httplug.collector.debug_collector" class="Http\HttplugBundle\Collector\DebugPluginCollector" public="false">
1011
<argument type="service" id="httplug.formatter.full_http_message"/>
12+
<argument type="service" id="httplug.collector.plugin_journal"/>
1113
<tag name="data_collector" template="HttplugBundle::webprofiler.html.twig" priority="200" id="httplug"/>
1214
</service>
1315
</services>

Resources/views/webprofiler.html.twig

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
{% for name, client in collector.clients %}
5454
<h3>{{ name }}</h3>
5555
{% for stackIndex in client.stackIndexKeys %}
56-
{{ macro.printMessages(client.requstStack(stackIndex), client.responseStack(stackIndex)) }}
56+
{{ macro.printMessages(client.requstStack(stackIndex), client.responseStack(stackIndex), collector.journal.plugins(name)) }}
5757
{% endfor %}
5858
{% else %}
5959
<div class="empty">
@@ -63,7 +63,7 @@
6363

6464
{% endblock %}
6565

66-
{% macro printMessages(requestStack, responseStack) %}
66+
{% macro printMessages(requestStack, responseStack, pluginNames) %}
6767
<table>
6868
<tr>
6969
<th width="50%">Request</th>
@@ -79,10 +79,13 @@
7979
<td colspan="2" style="text-align:center">See all</td>
8080
</tr>
8181
{% for idx in 1..requestStack|length-1 %}
82-
<tr>
83-
<td>{{ requestStack[idx]|nl2br }}</td>
84-
<td>{{ responseStack[idx]|nl2br }}</td>
85-
</tr>
82+
<tr>
83+
<td colspan="2" style="">{{ pluginNames[idx-1] }}</td>
84+
</tr>
85+
<tr>
86+
<td>{{ requestStack[idx]|nl2br }}</td>
87+
<td>{{ responseStack[idx]|nl2br }}</td>
88+
</tr>
8689
{% endfor %}
8790
{% endif %}
8891
</table>

0 commit comments

Comments
 (0)