| @@ 18-43 (lines=26) @@ | ||
| 15 | /** |
|
| 16 | * Analytics service provider |
|
| 17 | */ |
|
| 18 | class AnalyticsServiceProvider implements ServiceProviderInterface |
|
| 19 | { |
|
| 20 | /** |
|
| 21 | * Registers the service provider with a DI container. |
|
| 22 | * |
|
| 23 | * @param Container $container The DI container. |
|
| 24 | * |
|
| 25 | * @return void |
|
| 26 | */ |
|
| 27 | public function register(Container $container): void |
|
| 28 | { |
|
| 29 | $container->share(Analytics::class, [$this, 'getAnalyticsService']); |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Get the Analytics class service |
|
| 34 | * |
|
| 35 | * @param Container $container The DI container. |
|
| 36 | * |
|
| 37 | * @return Analytics |
|
| 38 | */ |
|
| 39 | public function getAnalyticsService(Container $container): Analytics |
|
| 40 | { |
|
| 41 | return new Analytics(true); |
|
| 42 | } |
|
| 43 | } |
|
| 44 | ||
| @@ 19-46 (lines=28) @@ | ||
| 16 | /** |
|
| 17 | * Repository service provider |
|
| 18 | */ |
|
| 19 | class RepositoryServiceProvider implements ServiceProviderInterface |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * Registers the service provider with a DI container. |
|
| 23 | * |
|
| 24 | * @param Container $container The DI container. |
|
| 25 | * |
|
| 26 | * @return void |
|
| 27 | */ |
|
| 28 | public function register(Container $container): void |
|
| 29 | { |
|
| 30 | $container->share(StatisticsRepository::class, [$this, 'getStatisticsRepositoryService']); |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * Get the StatisticsRepository service |
|
| 35 | * |
|
| 36 | * @param Container $container The DI container. |
|
| 37 | * |
|
| 38 | * @return StatisticsRepository |
|
| 39 | */ |
|
| 40 | public function getStatisticsRepositoryService(Container $container): StatisticsRepository |
|
| 41 | { |
|
| 42 | return new StatisticsRepository( |
|
| 43 | $container->get(DatabaseInterface::class) |
|
| 44 | ); |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||