|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the PommProject/PommBundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) 2014 Grégoire HUBERT <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace PommProject\PommBundle\DependencyInjection; |
|
11
|
|
|
|
|
12
|
|
|
use Symfony\Component\Config\FileLocator; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* PommExtension |
|
21
|
|
|
* |
|
22
|
|
|
* DIC extension |
|
23
|
|
|
* |
|
24
|
|
|
* @package PommBundle |
|
25
|
|
|
* @copyright 2014 Grégoire HUBERT |
|
26
|
|
|
* @author Nicolas JOSEPH |
|
27
|
|
|
* @license X11 {@link http://opensource.org/licenses/mit-license.php} |
|
28
|
|
|
* @see Extension |
|
29
|
|
|
*/ |
|
30
|
|
|
class PommExtension extends Extension |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* load |
|
34
|
|
|
* |
|
35
|
|
|
* @see Extension |
|
36
|
|
|
*/ |
|
37
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
38
|
|
|
{ |
|
39
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
40
|
|
|
$loader->load('services/pomm.yml'); |
|
41
|
|
|
|
|
42
|
|
|
$loader->load('services/profiler.yml'); |
|
43
|
|
|
|
|
44
|
|
|
$configuration = new Configuration(); |
|
45
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
46
|
|
|
|
|
47
|
|
|
$this->configure($config, $container); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* configure |
|
52
|
|
|
* |
|
53
|
|
|
* Configure the DIC using configuration file. |
|
54
|
|
|
* |
|
55
|
|
|
* @access public |
|
56
|
|
|
* @param array $config |
|
57
|
|
|
* @param ContainerBuilder $container |
|
58
|
|
|
* @return null |
|
59
|
|
|
*/ |
|
60
|
|
|
public function configure(array $config, ContainerBuilder $container) |
|
61
|
|
|
{ |
|
62
|
|
|
$definition = $container->getDefinition('pomm'); |
|
63
|
|
|
|
|
64
|
|
|
$container->setAlias('PommProject\Foundation\Pomm', new Alias('pomm', false)); |
|
65
|
|
|
$container->setParameter('pomm.configuration', $config['configuration']); |
|
66
|
|
|
|
|
67
|
|
|
if (isset($config['logger']['service'])) { |
|
68
|
|
|
$service = $config['logger']['service']; |
|
69
|
|
|
|
|
70
|
|
|
if (is_string($service) && strpos($service, '@') === 0) { |
|
71
|
|
|
$definition |
|
72
|
|
|
->addMethodCall('setLogger', [new Reference(substr($service, 1))]); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|