|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Joomla! Statistics Server |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved. |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Joomla\StatsServer\Providers; |
|
10
|
|
|
|
|
11
|
|
|
use Joomla\DI\Container; |
|
12
|
|
|
use Joomla\DI\ServiceProviderInterface; |
|
13
|
|
|
use Joomla\Event\Dispatcher; |
|
14
|
|
|
use Joomla\Event\DispatcherInterface; |
|
15
|
|
|
use Joomla\StatsServer\EventListener\AnalyticsSubscriber; |
|
16
|
|
|
use Joomla\StatsServer\EventListener\ErrorSubscriber; |
|
17
|
|
|
use Psr\Log\LoggerInterface; |
|
18
|
|
|
use TheIconic\Tracking\GoogleAnalytics\Analytics; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Event service provider |
|
22
|
|
|
*/ |
|
23
|
|
|
class EventServiceProvider implements ServiceProviderInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Registers the service provider with a DI container. |
|
27
|
|
|
* |
|
28
|
|
|
* @param Container $container The DI container. |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
12 |
|
public function register(Container $container): void |
|
33
|
|
|
{ |
|
34
|
12 |
|
$container->alias(Dispatcher::class, DispatcherInterface::class) |
|
35
|
12 |
|
->share(DispatcherInterface::class, [$this, 'getDispatcherService']); |
|
36
|
|
|
|
|
37
|
12 |
|
$container->share(AnalyticsSubscriber::class, [$this, 'getAnalyticsSubscriberService']) |
|
38
|
12 |
|
->tag('event.subscriber', [AnalyticsSubscriber::class]); |
|
39
|
|
|
|
|
40
|
12 |
|
$container->share(ErrorSubscriber::class, [$this, 'getErrorSubscriberService']) |
|
41
|
12 |
|
->tag('event.subscriber', [ErrorSubscriber::class]); |
|
42
|
12 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the AnalyticsSubscriber service |
|
46
|
|
|
* |
|
47
|
|
|
* @param Container $container The DI container. |
|
48
|
|
|
* |
|
49
|
|
|
* @return AnalyticsSubscriber |
|
50
|
|
|
*/ |
|
51
|
10 |
|
public function getAnalyticsSubscriberService(Container $container): AnalyticsSubscriber |
|
52
|
|
|
{ |
|
53
|
10 |
|
$subscriber = new AnalyticsSubscriber($container->get(Analytics::class)); |
|
54
|
10 |
|
$subscriber->setLogger($container->get(LoggerInterface::class)); |
|
55
|
|
|
|
|
56
|
10 |
|
return $subscriber; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get the DispatcherInterface service |
|
61
|
|
|
* |
|
62
|
|
|
* @param Container $container The DI container. |
|
63
|
|
|
* |
|
64
|
|
|
* @return DispatcherInterface |
|
65
|
|
|
*/ |
|
66
|
10 |
|
public function getDispatcherService(Container $container): DispatcherInterface |
|
67
|
|
|
{ |
|
68
|
10 |
|
$dispatcher = new Dispatcher; |
|
69
|
|
|
|
|
70
|
10 |
|
foreach ($container->getTagged('event.subscriber') as $subscriber) |
|
71
|
|
|
{ |
|
72
|
10 |
|
$dispatcher->addSubscriber($subscriber); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
10 |
|
return $dispatcher; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get the ErrorSubscriber service |
|
80
|
|
|
* |
|
81
|
|
|
* @param Container $container The DI container. |
|
82
|
|
|
* |
|
83
|
|
|
* @return ErrorSubscriber |
|
84
|
|
|
*/ |
|
85
|
10 |
|
public function getErrorSubscriberService(Container $container): ErrorSubscriber |
|
86
|
|
|
{ |
|
87
|
10 |
|
$subscriber = new ErrorSubscriber; |
|
88
|
10 |
|
$subscriber->setLogger($container->get(LoggerInterface::class)); |
|
89
|
|
|
|
|
90
|
10 |
|
return $subscriber; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|