1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dziki\MonologSentryBundle\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use Dziki\MonologSentryBundle\Processor\TagAppending; |
8
|
|
|
use Dziki\MonologSentryBundle\SubscribedProcessor\BrowserDataAppending; |
9
|
|
|
use Dziki\MonologSentryBundle\SubscribedProcessor\UserDataAppending; |
10
|
|
|
use Dziki\MonologSentryBundle\UserAgent\CachedParser; |
11
|
|
|
use Dziki\MonologSentryBundle\UserAgent\NativeParser; |
12
|
|
|
use Dziki\MonologSentryBundle\UserAgent\PhpUserAgentParser; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
15
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
16
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
17
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
18
|
|
|
|
19
|
|
|
class MonologSentryExtension extends Extension |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Loads a specific configuration. |
23
|
|
|
* |
24
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
25
|
|
|
*/ |
26
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
27
|
|
|
{ |
28
|
|
|
$configs = $this->processConfiguration(new Configuration(), $configs); |
|
|
|
|
29
|
|
|
|
30
|
|
|
if ($configs['user_context']) { |
31
|
|
|
$container->setDefinition( |
32
|
|
|
'dziki.monolog_sentry_bundle.user_data_appending_subscribed_processor', |
33
|
|
|
new Definition(UserDataAppending::class, [new Reference(TokenStorageInterface::class)]) |
34
|
|
|
) |
35
|
|
|
->setPrivate(true) |
36
|
|
|
->addTag('kernel.event_subscriber') |
37
|
|
|
->addTag('monolog.processor') |
38
|
|
|
; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($configs['user_agent_parser']) { |
42
|
|
|
$handlerName = $configs['user_agent_parser']; |
43
|
|
|
switch ($handlerName) { |
44
|
|
|
case 'native': |
45
|
|
|
$parserClass = NativeParser::class; |
46
|
|
|
$container->setDefinition($parserClass, new Definition($parserClass)) |
47
|
|
|
->setPrivate(true) |
48
|
|
|
; |
49
|
|
|
break; |
50
|
|
|
case 'phpuseragent': |
51
|
|
|
$parserClass = PhpUserAgentParser::class; |
52
|
|
|
$container->setDefinition($parserClass, new Definition($parserClass)) |
53
|
|
|
->setPrivate(true) |
54
|
|
|
; |
55
|
|
|
break; |
56
|
|
|
default: |
57
|
|
|
$parserClass = $handlerName; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($configs['cache']) { |
61
|
|
|
$container->setDefinition( |
62
|
|
|
CachedParser::class, |
63
|
|
|
new Definition( |
64
|
|
|
CachedParser::class, |
65
|
|
|
[ |
66
|
|
|
new Reference($configs['cache']), |
67
|
|
|
new Reference($parserClass), |
68
|
|
|
] |
69
|
|
|
) |
70
|
|
|
)->setPrivate(true) |
71
|
|
|
; |
72
|
|
|
|
73
|
|
|
$parserClass = CachedParser::class; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$container->setDefinition( |
77
|
|
|
'dziki.monolog_sentry_bundle.browser_data_appending_subscribed_processor', |
78
|
|
|
new Definition(BrowserDataAppending::class, [new Reference($parserClass)]) |
79
|
|
|
) |
80
|
|
|
->setPrivate(true) |
81
|
|
|
->addTag('kernel.event_subscriber') |
82
|
|
|
->addTag('monolog.processor') |
83
|
|
|
; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (\is_array($configs['tags'])) { |
87
|
|
|
foreach ($configs['tags'] as $tag => ['value' => $value, 'name' => $name]) { |
88
|
|
|
$tagName = $name ?: $tag; |
89
|
|
|
$container->setDefinition( |
90
|
|
|
"dziki.monolog_sentry_bundle.{$tag}_appending_processor", |
91
|
|
|
new Definition( |
92
|
|
|
TagAppending::class, |
93
|
|
|
[ |
94
|
|
|
$tagName, |
95
|
|
|
$value, |
96
|
|
|
] |
97
|
|
|
) |
98
|
|
|
) |
99
|
|
|
->setPrivate(true) |
100
|
|
|
->addTag('monolog.processor') |
101
|
|
|
; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|