|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Facile\SentryModule\Service; |
|
6
|
|
|
|
|
7
|
|
|
use Facile\SentryModule\Exception\InvalidArgumentException; |
|
8
|
|
|
use Facile\SentryModule\Options\Configuration; |
|
9
|
|
|
use Facile\SentryModule\Options\ConfigurationInterface; |
|
10
|
|
|
use Facile\SentryModule\Options\ErrorHandlerOptions; |
|
11
|
|
|
use Facile\SentryModule\Options\StackTraceOptions; |
|
12
|
|
|
use Facile\SentryModule\SendCallback\CallbackChain; |
|
13
|
|
|
use Interop\Container\ContainerInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class ConfigurationFactory. |
|
17
|
|
|
*/ |
|
18
|
|
|
final class ConfigurationFactory |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @param ContainerInterface $container |
|
22
|
|
|
* @return ConfigurationInterface |
|
23
|
|
|
*/ |
|
24
|
3 |
|
public function __invoke(ContainerInterface $container): ConfigurationInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var array $config */ |
|
27
|
3 |
|
$config = $container->get('config'); |
|
28
|
|
|
|
|
29
|
3 |
|
$configuration = $config['facile']['sentry'] ?? []; |
|
30
|
3 |
|
$ravenOptions = $configuration['raven_options'] ?? []; |
|
31
|
|
|
|
|
32
|
3 |
|
if (! array_key_exists('logger', $ravenOptions)) { |
|
33
|
3 |
|
$ravenOptions['logger'] = 'SentryModule'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
3 |
|
if (array_key_exists('send_callback', $ravenOptions)) { |
|
37
|
1 |
|
$ravenOptions['send_callback'] = $this->buildCallbackChain($container, $ravenOptions['send_callback']); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
3 |
|
if (array_key_exists('transport', $ravenOptions)) { |
|
41
|
1 |
|
$transport = $ravenOptions['transport']; |
|
42
|
1 |
|
if (is_string($transport)) { |
|
43
|
1 |
|
$transport = $container->get($transport); |
|
44
|
|
|
} |
|
45
|
1 |
|
$ravenOptions['transport'] = $transport; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
3 |
|
$configuration['raven_options'] = $ravenOptions; |
|
49
|
|
|
|
|
50
|
3 |
|
$configuration['error_handler_options'] = new ErrorHandlerOptions( |
|
51
|
3 |
|
$configuration['error_handler_options'] ?? [] |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
3 |
|
$configuration['stack_trace_options'] = new StackTraceOptions( |
|
55
|
3 |
|
$configuration['stack_trace_options'] ?? [] |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
3 |
|
return new Configuration($configuration); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param ContainerInterface $container |
|
64
|
|
|
* @param array|string|callable $callbackOptions |
|
65
|
|
|
* |
|
66
|
|
|
* @return CallbackChain |
|
67
|
|
|
* @throws \Facile\SentryModule\Exception\InvalidArgumentException |
|
68
|
|
|
*/ |
|
69
|
1 |
|
private function buildCallbackChain(ContainerInterface $container, $callbackOptions): CallbackChain |
|
70
|
|
|
{ |
|
71
|
1 |
|
if (null === $callbackOptions) { |
|
72
|
|
|
return new CallbackChain(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
$callbackOptions = (array) $callbackOptions; |
|
76
|
1 |
|
$callbacks = []; |
|
77
|
|
|
|
|
78
|
1 |
|
foreach ($callbackOptions as $callbackItem) { |
|
79
|
1 |
|
if (is_string($callbackItem) && $container->has($callbackItem)) { |
|
80
|
1 |
|
$callbackItem = $container->get($callbackItem); |
|
81
|
|
|
} |
|
82
|
1 |
|
if (! $this->isValidCallback($container, $callbackItem)) { |
|
|
|
|
|
|
83
|
|
|
throw new InvalidArgumentException('Invalid callback'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
$callbacks[] = $callbackItem; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
1 |
|
return new CallbackChain($callbacks); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param ContainerInterface $container |
|
94
|
|
|
* @param callable|string $callbackItem |
|
95
|
|
|
* @return bool |
|
96
|
|
|
* @throws \Facile\SentryModule\Exception\InvalidArgumentException |
|
97
|
|
|
*/ |
|
98
|
1 |
|
private function isValidCallback(ContainerInterface $container, $callbackItem): bool |
|
99
|
|
|
{ |
|
100
|
1 |
|
return is_callable($callbackItem) || (is_string($callbackItem) && $container->has($callbackItem)); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: