1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ftrrtf\RollbarBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* FtrrtfRollbarExtension. |
12
|
|
|
*/ |
13
|
|
|
class FtrrtfRollbarExtension extends Extension |
14
|
|
|
{ |
15
|
|
|
public function load(array $configs, ContainerBuilder $container) |
16
|
|
|
{ |
17
|
|
|
$configuration = new Configuration(); |
18
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
19
|
|
|
|
20
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
21
|
|
|
|
22
|
|
|
if (isset($config['notifier'])) { |
23
|
|
|
$loader->load('services.xml'); |
24
|
|
|
$container->setParameter('ftrrtf_rollbar.environment.options', $config['environment']); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
if (isset($config['notifier']['client'])) { |
28
|
|
|
$container->setParameter('ftrrtf_rollbar.notifier.client.options', $config['notifier']['client']); |
29
|
|
|
if (isset($config['notifier']['client']['check_ignore_function_provider'])) { |
30
|
|
|
$container->setParameter( |
31
|
|
|
'ftrrtf_rollbar.notifier.client.check_ignore_function_provider', |
32
|
|
|
$config['notifier']['client']['check_ignore_function_provider'] |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if (isset($config['notifier']['client']['transform_payload_function_provider'])) { |
37
|
|
|
$container->setParameter( |
38
|
|
|
'ftrrtf_rollbar.notifier.client.transform_payload_function_provider', |
39
|
|
|
$config['notifier']['client']['transform_payload_function_provider'] |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$loader->load('client.xml'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (isset($config['notifier']['server'])) { |
47
|
|
|
if (isset($config['notifier']['server']['transport']['type'])) { |
48
|
|
|
$transport = $config['notifier']['server']['transport']; |
49
|
|
|
switch ($transport['type']) { |
50
|
|
|
case 'agent': |
51
|
|
|
$container->setParameter( |
52
|
|
|
'ftrrtf_rollbar.transport.agent_log_location', |
53
|
|
|
$transport['agent_log_location'] |
54
|
|
|
); |
55
|
|
|
$loader->load('transport_agent.xml'); |
56
|
|
|
$this->prepareLogsDir( |
57
|
|
|
$container->getParameterBag()->resolveValue($transport['agent_log_location']) |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
break; |
61
|
|
|
case 'curl': |
62
|
|
|
default: |
63
|
|
|
$container->setParameter('ftrrtf_rollbar.transport.access_token', $transport['access_token']); |
64
|
|
|
$loader->load('transport_curl.xml'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
unset($config['notifier']['server']['transport']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$container->setParameter('ftrrtf_rollbar.notifier.server.options', $config['notifier']['server']); |
71
|
|
|
|
72
|
|
|
$loader->load('server.xml'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getAlias() |
80
|
|
|
{ |
81
|
|
|
return 'ftrrtf_rollbar'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Create logs dir if does not exist. |
86
|
|
|
* |
87
|
|
|
* @param $logsDir |
88
|
|
|
* |
89
|
|
|
* @throws \RuntimeException |
90
|
|
|
*/ |
91
|
|
|
private function prepareLogsDir($logsDir) |
92
|
|
|
{ |
93
|
|
|
if (!is_dir($logsDir)) { |
94
|
|
|
if (false === @mkdir($logsDir, 0777, true) && !is_dir($logsDir)) { |
95
|
|
|
throw new \RuntimeException(sprintf("Unable to create the logs directory (%s)\n", $logsDir)); |
96
|
|
|
} |
97
|
|
|
} elseif (!is_writable($logsDir)) { |
98
|
|
|
throw new \RuntimeException(sprintf("Unable to write in the logs directory (%s)\n", $logsDir)); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|