Skip to content

Commit 95fd95f

Browse files
committed
Add a way to add additional collectors
1 parent 9592bb1 commit 95fd95f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

etc/di/event-loop.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
<?php declare(strict_types=1);
22

3+
use function EventLoop\getLoop;
4+
use React\EventLoop\LoopInterface;
35
use ReactInspector\EventLoop\LoopCollector;
46
use ReactInspector\MemoryUsage\MemoryUsageCollector;
57
use ReactInspector\Metrics;
68
use ReactInspector\MetricsStreamInterface;
79
use ReactInspector\Stream\IOCollector;
8-
use function EventLoop\getLoop;
9-
use React\EventLoop\LoopInterface;
1010

1111
return [
1212
LoopInterface::class => function () {
1313
return getLoop();
1414
},
15-
MetricsStreamInterface::class => function (LoopInterface $loop) {
15+
MetricsStreamInterface::class => function (LoopInterface $loop, AdditionalCollectors $additionalCollectors) {
1616
return new Metrics(
1717
$loop,
1818
1,
1919
new LoopCollector($loop),
2020
new MemoryUsageCollector($loop),
21-
new IOCollector()
21+
new IOCollector(),
22+
...$additionalCollectors->get()
2223
);
2324
},
2425
];

src/AdditionalCollectors.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use ReactInspector\CollectorInterface;
4+
5+
final class AdditionalCollectors
6+
{
7+
private $collectors = [];
8+
9+
public function add(CollectorInterface $collector): void
10+
{
11+
$this->collectors[] = $collector;
12+
}
13+
14+
public function get(): array
15+
{
16+
return $this->collectors;
17+
}
18+
}
19+

0 commit comments

Comments
 (0)