Skip to content

Commit eec8c7c

Browse files
fbourigaultNyholm
authored andcommitted
guess client names from collected stacks (#180)
1 parent 9df8e66 commit eec8c7c

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

Collector/Collector.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@
2020
*/
2121
class Collector extends DataCollector
2222
{
23-
/**
24-
* @param array $clients
25-
*/
26-
public function __construct(array $clients)
23+
public function __construct()
2724
{
2825
$this->data['stacks'] = [];
29-
$this->data['clients'] = $clients;
3026
}
3127

3228
/**
@@ -98,7 +94,9 @@ public function getFailedStacks()
9894
*/
9995
public function getClients()
10096
{
101-
return $this->data['clients'];
97+
return array_unique(array_map(function (Stack $stack) {
98+
return $stack->getClient();
99+
}, $this->data['stacks']));
102100
}
103101

104102
/**

DependencyInjection/HttplugExtension.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ private function configureClients(ContainerBuilder $container, array $config, $p
110110
$container->setAlias('httplug.client.default', 'httplug.client.'.$first);
111111
}
112112
}
113-
114-
if ($profiling) {
115-
$container->getDefinition('httplug.collector.collector')
116-
->setArguments([$clients])
117-
;
118-
}
119113
}
120114

121115
/**
@@ -452,11 +446,6 @@ function ($id) {
452446
])
453447
;
454448

455-
if ($profiling) {
456-
$collector = $container->getDefinition('httplug.collector.collector');
457-
$collector->replaceArgument(0, array_merge($collector->getArgument(0), [$name]));
458-
}
459-
460449
return $serviceId;
461450
}
462451

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Http\HttplugBundle\Tests\Unit\Collector;
4+
5+
use Http\HttplugBundle\Collector\Collector;
6+
use Http\HttplugBundle\Collector\Stack;
7+
8+
class CollectorTest extends \PHPUnit_Framework_TestCase
9+
{
10+
public function testCollectClientNames()
11+
{
12+
$collector = new Collector();
13+
14+
$collector->addStack(new Stack('default', 'GET / HTTP/1.1'));
15+
$collector->addStack(new Stack('acme', 'GET / HTTP/1.1'));
16+
$collector->addStack(new Stack('acme', 'GET / HTTP/1.1'));
17+
18+
$this->assertEquals(['default', 'acme'], $collector->getClients());
19+
}
20+
}

0 commit comments

Comments
 (0)