1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Norsys\LogsBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
7
|
|
|
use Symfony\Component\Config\FileLocator; |
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
10
|
|
|
use Doctrine\DBAL\DriverManager; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This is the class that loads and manages your bundle configuration |
14
|
|
|
* |
15
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
16
|
|
|
*/ |
17
|
|
|
class NorsysLogsExtension extends Extension |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param array $configs |
21
|
|
|
* @param ContainerBuilder $container |
22
|
|
|
*/ |
23
|
|
|
public function load(array $configs, ContainerBuilder $container) |
24
|
|
|
{ |
25
|
|
|
$configuration = new Configuration(); |
26
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
27
|
|
|
|
28
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
29
|
|
|
$loader->load('services.xml'); |
30
|
|
|
|
31
|
|
|
$container->setParameter('norsys_logs.security.enabled', $config['security']['enabled']); |
32
|
|
|
$container->setParameter('norsys_logs.security.allowed_ips', $config['security']['allowed_ips']); |
33
|
|
|
$container->setParameter('norsys_logs.base_layout', $config['base_layout']); |
34
|
|
|
$container->setParameter('norsys_logs.logs_per_page', $config['logs_per_page']); |
35
|
|
|
|
36
|
|
|
$container->setParameter('norsys_logs.doctrine.table_name', $config['doctrine']['table_name']); |
37
|
|
|
|
38
|
|
|
if (isset($config['doctrine']['connection_name']) === true) { |
39
|
|
|
$container->setAlias( |
40
|
|
|
'norsys_logs.doctrine_dbal.connection', |
41
|
|
|
sprintf('doctrine.dbal.%s_connection', $config['doctrine']['connection_name']) |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (isset($config['doctrine']['connection']) === true) { |
46
|
|
|
$connectionDefinition = new Definition( |
47
|
|
|
'Doctrine\DBAL\Connection', |
48
|
|
|
array($config['doctrine']['connection']) |
49
|
|
|
); |
50
|
|
|
$connectionDefinition->setFactory('Doctrine\DBAL\DriverManager::getConnection'); |
51
|
|
|
$container->setDefinition('norsys_logs.doctrine_dbal.connection', $connectionDefinition); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|