|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Facile\SentryModule\Service; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Container\ContainerInterface; |
|
8
|
|
|
use Sentry\ClientBuilder; |
|
9
|
|
|
use Sentry\ClientInterface; |
|
10
|
|
|
|
|
11
|
|
|
final class ClientConfigFactory |
|
12
|
|
|
{ |
|
13
|
|
|
public function __invoke(ContainerInterface $container): ClientInterface |
|
14
|
|
|
{ |
|
15
|
|
|
$config = $container->get('config')['sentry']; |
|
16
|
|
|
|
|
17
|
|
|
$options = \array_filter( |
|
18
|
|
|
$config['options'] ?? [], |
|
19
|
|
|
static function ($value) { |
|
20
|
|
|
return null !== $value; |
|
21
|
|
|
} |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
$resolves = [ |
|
25
|
|
|
'before_breadcrumbs', |
|
26
|
|
|
'before_send', |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
$options = \array_merge( |
|
30
|
|
|
$options, |
|
31
|
|
|
\array_map( |
|
32
|
|
|
static function (string $value) use ($container): callable { |
|
33
|
|
|
return $container->get($value); |
|
34
|
|
|
}, |
|
35
|
|
|
\array_intersect_key($options, \array_flip($resolves)) |
|
36
|
|
|
) |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$builder = ClientBuilder::create($options); |
|
40
|
|
|
|
|
41
|
|
|
if (\is_string($config['transport'] ?? null)) { |
|
42
|
|
|
$builder->setTransport($container->get($config['transport'])); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (\is_string($config['http_client'] ?? null)) { |
|
46
|
|
|
$builder->setHttpClient($container->get($config['http_client'])); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (\is_string($config['message_factory'] ?? null)) { |
|
50
|
|
|
$builder->setMessageFactory($container->get($config['message_factory'])); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (\is_string($config['uri_factory'] ?? null)) { |
|
54
|
|
|
$builder->setUriFactory($container->get($config['uri_factory'])); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (\is_string($config['representation_serializer'] ?? null)) { |
|
58
|
|
|
$builder->setRepresentationSerializer($container->get($config['representation_serializer'])); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (\is_string($config['serializer'] ?? null)) { |
|
62
|
|
|
$builder->setSerializer($container->get($config['serializer'])); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $builder->getClient(); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|