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
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
|
|
public function load(array $configs, ContainerBuilder $container) |
19
|
|
|
{ |
20
|
|
|
$configuration = new Configuration(); |
21
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
22
|
|
|
|
23
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
24
|
|
|
|
25
|
|
|
if (isset($config['notifier'])) { |
26
|
|
|
$loader->load('services.xml'); |
27
|
|
|
$container->setParameter('ftrrtf_rollbar.environment.options', $config['environment']); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if (isset($config['notifier']['client'])) { |
31
|
|
|
$container->setParameter('ftrrtf_rollbar.notifier.client.options', $config['notifier']['client']); |
32
|
|
|
$loader->load('client.xml'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (isset($config['notifier']['server'])) { |
36
|
|
|
if (isset($config['notifier']['server']['transport']['type'])) { |
37
|
|
|
$transport = $config['notifier']['server']['transport']; |
38
|
|
|
switch ($transport['type']) { |
39
|
|
|
case 'agent': |
40
|
|
|
$container->setParameter('ftrrtf_rollbar.transport.agent_log_location', $transport['agent_log_location']); |
|
|
|
|
41
|
|
|
$loader->load('transport_agent.xml'); |
42
|
|
|
$this->prepareLogsDir( |
43
|
|
|
$container->getParameterBag()->resolveValue($transport['agent_log_location']) |
44
|
|
|
); |
45
|
|
|
break; |
46
|
|
|
case 'curl': |
47
|
|
|
default: |
48
|
|
|
$container->setParameter('ftrrtf_rollbar.transport.access_token', $transport['access_token']); |
49
|
|
|
$loader->load('transport_curl.xml'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
unset($config['notifier']['server']['transport']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$container->setParameter('ftrrtf_rollbar.notifier.server.options', $config['notifier']['server']); |
56
|
|
|
|
57
|
|
|
$loader->load('server.xml'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function getAlias() |
65
|
|
|
{ |
66
|
|
|
return 'ftrrtf_rollbar'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Prepare logs dir |
71
|
|
|
* |
72
|
|
|
* @param $logsDir |
73
|
|
|
* @throws \RuntimeException |
74
|
|
|
*/ |
75
|
|
|
private function prepareLogsDir($logsDir) |
76
|
|
|
{ |
77
|
|
|
if (!is_dir($logsDir)) { |
78
|
|
|
if (false === @mkdir($logsDir, 0777, true) && !is_dir($logsDir)) { |
79
|
|
|
throw new \RuntimeException(sprintf("Unable to create the logs directory (%s)\n", $logsDir)); |
80
|
|
|
} |
81
|
|
|
} elseif (!is_writable($logsDir)) { |
82
|
|
|
throw new \RuntimeException(sprintf("Unable to write in the logs directory (%s)\n", $logsDir)); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.