|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Facile\SentryModule\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Facile\SentryModule\Options\ClientOptions; |
|
6
|
|
|
use Facile\SentryModule\Processor\SanitizeDataProcessor; |
|
7
|
|
|
use Facile\SentryModule\SendCallback\CallbackChain; |
|
8
|
|
|
use Interop\Container\ContainerInterface; |
|
9
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ClientFactory. |
|
13
|
|
|
*/ |
|
14
|
|
|
class ClientFactory extends AbstractFactory |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @param ContainerInterface $container |
|
18
|
|
|
* @param array|string|callable $callbackOptions |
|
19
|
|
|
* |
|
20
|
|
|
* @return CallbackChain |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function buildCallbackChain(ContainerInterface $container, $callbackOptions) |
|
23
|
|
|
{ |
|
24
|
|
|
$callbackChain = new CallbackChain(); |
|
25
|
|
|
|
|
26
|
|
|
if (null === $callbackOptions) { |
|
27
|
|
|
return $callbackChain; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
if (is_callable($callbackOptions) || !is_array($callbackOptions)) { |
|
31
|
|
|
$callbackOptions = [$callbackOptions]; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
foreach ($callbackOptions as $callbackItem) { |
|
35
|
|
|
if (is_string($callbackItem)) { |
|
36
|
|
|
$callbackItem = $container->get($callbackItem); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$callbackChain->addCallback($callbackItem); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return $callbackChain; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param ContainerInterface $container |
|
47
|
|
|
* @param string $requestedName |
|
48
|
|
|
* @param array|null $options |
|
49
|
|
|
* |
|
50
|
|
|
* @return Client |
|
51
|
|
|
* |
|
52
|
|
|
* @throws \RuntimeException |
|
53
|
|
|
* @throws \Interop\Container\Exception\NotFoundException |
|
54
|
|
|
* @throws \Interop\Container\Exception\ContainerException |
|
55
|
|
|
*/ |
|
56
|
2 |
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var ClientOptions $options */ |
|
59
|
2 |
|
$options = $this->getOptions($container, 'client'); |
|
60
|
|
|
|
|
61
|
2 |
|
$ravenOptions = $options->getOptions(); |
|
62
|
|
|
|
|
63
|
2 |
|
if (!array_key_exists('processors', $ravenOptions)) { |
|
64
|
2 |
|
$ravenOptions['processors'] = [SanitizeDataProcessor::class]; |
|
65
|
2 |
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
if (!array_key_exists('logger', $ravenOptions)) { |
|
68
|
2 |
|
$ravenOptions['logger'] = 'SentryModule'; |
|
69
|
2 |
|
} |
|
70
|
|
|
|
|
71
|
2 |
|
if (array_key_exists('send_callback', $ravenOptions)) { |
|
72
|
|
|
$ravenOptions['send_callback'] = $this->buildCallbackChain($container, $ravenOptions['send_callback']); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
2 |
|
if (array_key_exists('transport', $ravenOptions)) { |
|
76
|
|
|
$transport = $ravenOptions['transport']; |
|
77
|
|
|
if (is_string($transport)) { |
|
78
|
|
|
$transport = $container->get($transport); |
|
79
|
|
|
} |
|
80
|
|
|
$ravenOptions['transport'] = $transport; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
2 |
|
$ravenClient = new \Raven_Client($options->getDsn(), $ravenOptions); |
|
84
|
|
|
|
|
85
|
2 |
|
$client = new Client($ravenClient, $options); |
|
86
|
|
|
|
|
87
|
2 |
|
$errorHandlerListener = $container->get($options->getErrorHandlerListener()); |
|
88
|
2 |
|
if ($errorHandlerListener instanceof ClientAwareInterface) { |
|
89
|
1 |
|
$errorHandlerListener->setClient($client); |
|
90
|
1 |
|
} |
|
91
|
2 |
|
$client->setErrorHandlerListener($errorHandlerListener); |
|
92
|
|
|
|
|
93
|
2 |
|
return $client; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
98
|
|
|
* |
|
99
|
|
|
* @return Client |
|
100
|
|
|
*/ |
|
101
|
1 |
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
102
|
|
|
{ |
|
103
|
1 |
|
return $this($serviceLocator, Client::class); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get the class name of the options associated with this factory. |
|
108
|
|
|
* |
|
109
|
|
|
* |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
2 |
|
public function getOptionsClass() |
|
113
|
|
|
{ |
|
114
|
2 |
|
return ClientOptions::class; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
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: