-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStatisticsManager.php
49 lines (40 loc) · 1.56 KB
/
StatisticsManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Abrouter\Client\Manager;
use Abrouter\Client\Events\EventDispatcher;
use Abrouter\Client\DTO\EventDTOInterface;
use Abrouter\Client\Events\Handlers\RelatedUsersStatisticsInterceptor;
use Abrouter\Client\Services\ExperimentsParallelRun\ParallelRunSwitch;
use Abrouter\Client\Services\Statistics\SendEventTask;
class StatisticsManager
{
private EventDispatcher $eventDispatcher;
private ParallelRunSwitch $parallelRunSwitch;
private RelatedUsersStatisticsInterceptor $relatedUsersStatisticsInterceptor;
/**
* @param EventDispatcher $eventDispatcher
* @param ParallelRunSwitch $parallelRunSwitch
* @param RelatedUsersStatisticsInterceptor $relatedUsersStatisticsInterceptor
*/
public function __construct(
EventDispatcher $eventDispatcher,
ParallelRunSwitch $parallelRunSwitch,
RelatedUsersStatisticsInterceptor $relatedUsersStatisticsInterceptor
) {
$this->eventDispatcher = $eventDispatcher;
$this->parallelRunSwitch = $parallelRunSwitch;
$this->relatedUsersStatisticsInterceptor = $relatedUsersStatisticsInterceptor;
}
public function sendEvent(EventDTOInterface $eventDTO): void
{
$task = new SendEventTask($eventDTO);
$isParallelRunningEnabled = $this->parallelRunSwitch->isEnabled();
if ($isParallelRunningEnabled) {
$this->relatedUsersStatisticsInterceptor->handle($task);
}
$this->eventDispatcher->dispatch(
$task,
$isParallelRunningEnabled
);
}
}