|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Facile\SentryModule\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Facile\SentryModule\Options\ClientOptions; |
|
6
|
|
|
use Facile\SentryModule\Processor\SanitizeDataProcessor; |
|
7
|
|
|
use Interop\Container\ContainerInterface; |
|
8
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class ClientFactory. |
|
12
|
|
|
*/ |
|
13
|
|
|
class ClientFactory extends AbstractFactory |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param ContainerInterface $container |
|
17
|
|
|
* @param string $requestedName |
|
18
|
|
|
* @param array|null $options |
|
19
|
|
|
* |
|
20
|
|
|
* @return Client |
|
21
|
|
|
* @throws \RuntimeException |
|
22
|
|
|
* |
|
23
|
|
|
* @throws \Interop\Container\Exception\NotFoundException |
|
24
|
|
|
* @throws \Interop\Container\Exception\ContainerException |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var ClientOptions $options */ |
|
29
|
2 |
|
$options = $this->getOptions($container, 'client'); |
|
30
|
|
|
|
|
31
|
2 |
|
$ravenOptions = $options->getOptions(); |
|
32
|
|
|
|
|
33
|
2 |
|
if (!array_key_exists('processors', $ravenOptions)) { |
|
34
|
2 |
|
$ravenOptions['processors'] = [SanitizeDataProcessor::class]; |
|
35
|
2 |
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
$ravenClient = new \Raven_Client($options->getDsn(), $ravenOptions); |
|
38
|
|
|
|
|
39
|
2 |
|
$client = new Client($ravenClient, $options); |
|
40
|
|
|
|
|
41
|
2 |
|
$errorHandlerListener = $container->get($options->getErrorHandlerListener()); |
|
42
|
2 |
|
if ($errorHandlerListener instanceof ClientAwareInterface) { |
|
43
|
1 |
|
$errorHandlerListener->setClient($client); |
|
44
|
1 |
|
} |
|
45
|
2 |
|
$client->setErrorHandlerListener($errorHandlerListener); |
|
46
|
|
|
|
|
47
|
2 |
|
return $client; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
52
|
|
|
* @return Client |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
55
|
|
|
{ |
|
56
|
1 |
|
return $this($serviceLocator, Client::class); |
|
57
|
1 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get the class name of the options associated with this factory. |
|
61
|
|
|
* |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
2 |
|
public function getOptionsClass() |
|
66
|
|
|
{ |
|
67
|
2 |
|
return ClientOptions::class; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|