File size: 1,420 Bytes
cf14c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
<?php

declare(strict_types=1);

namespace Stat\Infrastructure;

use Application;
use Billing\Domain\Events\CreditUsageEvent;
use Billing\Domain\Events\OrderCreatedEvent;
use Billing\Domain\Events\SubscriptionCreatedEvent;
use Easy\EventDispatcher\Mapper\ArrayMapper;
use Override;
use Shared\Infrastructure\BootstrapperInterface;
use Stat\Domain\Repositories\StatRepositoryInterface;
use Stat\Infrastructure\Listeners\SaveStat;
use Stat\Infrastructure\Repositories\DoctrineOrm\StatRepository;
use User\Domain\Events\UserCreatedEvent;

class StatModuleBootstrapper implements BootstrapperInterface
{
    public function __construct(
        private Application $app,
        private ArrayMapper $arrayMapper,
    ) {
    }

    #[Override]
    public function bootstrap(): void
    {
        $this->app->set(
            StatRepositoryInterface::class,
            StatRepository::class
        );

        $this->arrayMapper
            ->addEventListener(
                CreditUsageEvent::class,
                SaveStat::class
            )
            ->addEventListener(
                UserCreatedEvent::class,
                SaveStat::class
            )
            ->addEventListener(
                SubscriptionCreatedEvent::class,
                SaveStat::class
            )
            ->addEventListener(
                OrderCreatedEvent::class,
                SaveStat::class
            );
    }
}