Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions Collector/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,55 @@ public function getFailedStacks()
*/
public function getClients()
{
$stacks = array_filter($this->data['stacks'], function (Stack $stack) {
return $stack->getParent() === null;
});

return array_unique(array_map(function (Stack $stack) {
return $stack->getClient();
}, $this->data['stacks']));
}, $stacks));
}

/**
* @param $client
*
* @return Stack[]
*/
public function getClientStacks($client)
public function getClientRootStacks($client)
{
return array_filter($this->data['stacks'], function (Stack $stack) use ($client) {
return $stack->getClient() == $client;
return $stack->getClient() == $client && $stack->getParent() == null;
});
}

/**
* Count all messages for a client.
*
* @param $client
*
* @return int
*/
public function countClientMessages($client)
{
return array_sum(array_map(function (Stack $stack) {
return $this->countStackMessages($stack);
}, $this->getClientRootStacks($client)));
}

/**
* Recursively count message in stack.
*
* @param Stack $stack
*
* @return int
*/
private function countStackMessages(Stack $stack)
{
return 1 + array_sum(array_map(function (Stack $child) {
return $this->countStackMessages($child);
}, $this->getChildrenStacks($stack)));
}

/**
* @return int
*/
Expand Down
4 changes: 2 additions & 2 deletions Resources/views/webprofiler.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
<div class="sf-tabs">
{% for client in collector.clients %}
<div class="tab">
<h3 class="tab-title">{{ client }} <span class="badge">{{ collector.clientStacks(client)|length }}</span></h3>
<h3 class="tab-title">{{ client }} <span class="badge">{{ collector.countClientMessages(client) }}</span></h3>

<div class="tab-content">
<p class="help">
These messages are sent by client named "{{ client }}".
</p>

{% for stack in collector.clientStacks(client) if not stack.parent %}
{% for stack in collector.clientRootStacks(client) %}
<div class="httplug-stack">
{% include '@Httplug/stack.html.twig' with {
'collector': collector,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Collector/CollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public function testAddStack()
$collector->addStack($stack);

$this->assertEquals(['acme'], $collector->getClients());
$this->assertEquals([$stack], $collector->getClientStacks('acme'));
$this->assertEquals([$stack], $collector->getClientRootStacks('acme'));
}
}