1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NVBooster\PHPCRAssetsBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
9
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This is the class that loads and manages your bundle configuration |
13
|
|
|
* |
14
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
15
|
|
|
*/ |
16
|
|
|
class NVBoosterPHPCRAssetsExtension extends Extension implements PrependExtensionInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
public function load(array $configs, ContainerBuilder $container) |
22
|
|
|
{ |
23
|
|
|
$configuration = new Configuration(); |
24
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
25
|
|
|
|
26
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
27
|
|
|
$loader->load('services.xml'); |
28
|
|
|
|
29
|
|
|
if (key_exists('codemirror', $config)) { |
30
|
|
|
$loader->load('form.xml'); |
31
|
|
|
|
32
|
|
|
if (key_exists('paths', $config['codemirror'])) { |
33
|
|
|
$container |
34
|
|
|
->getDefinition('nvbooster_assets.twig_extension') |
35
|
|
|
->addArgument($config['codemirror']['paths']); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$container |
39
|
|
|
->getDefinition('nvbooster_assets.formtype.asset') |
40
|
|
|
->addArgument(array_merge( |
41
|
|
|
array( |
42
|
|
|
'theme' => 'eclipse', |
43
|
|
|
'mode' => 'xml', |
44
|
|
|
'lineNumbers' => true |
45
|
|
|
|
46
|
|
|
), $config['codemirror']['options'] |
47
|
|
|
)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
51
|
|
|
if (isset($bundles['SonataAdminBundle'])) { |
52
|
|
|
$loader->load('admin.xml'); |
53
|
|
|
|
54
|
|
|
if (key_exists('codemirror', $config)) { |
55
|
|
|
$container |
56
|
|
|
->getDefinition('nvbooster_assets.asset_admin') |
57
|
|
|
->addMethodCall('enableCodeMirror'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$container |
62
|
|
|
->getDefinition('nvbooster_assets.routing.prefix_provider') |
63
|
|
|
->replaceArgument(0, $config['routing']['base_uri']); |
64
|
|
|
|
65
|
|
|
if ($config['phpcr']['root_path']) { |
66
|
|
|
$container->setParameter('nvbooster_assets.phpcr.root', $config['phpcr']['root_path']); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$root = $container->getParameter('nvbooster_assets.phpcr.root'); |
70
|
|
|
|
71
|
|
|
$container |
72
|
|
|
->getDefinition('nvbooster_assets.phpcr.initializer') |
73
|
|
|
->addArgument(array($root)); |
74
|
|
|
|
75
|
|
|
$container |
76
|
|
|
->getDefinition('nvbooster_assets.controller') |
77
|
|
|
->addArgument($config['filters']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function prepend(ContainerBuilder $container) |
84
|
|
|
{ |
85
|
|
|
$config = array( |
86
|
|
|
'dynamic' => array( |
87
|
|
|
'controllers_by_class' => array( |
88
|
|
|
'NVBooster\PHPCRAssetsBundle\Asset\JsAsset' => 'nvbooster_assets.controller:serveJs', |
89
|
|
|
'NVBooster\PHPCRAssetsBundle\Asset\CssAsset' => 'nvbooster_assets.controller:serveCss', |
90
|
|
|
'NVBooster\PHPCRAssetsBundle\Asset\BaseAsset' => 'nvbooster_assets.controller:serveAsset' |
91
|
|
|
) |
92
|
|
|
) |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$container->prependExtensionConfig('cmf_routing', $config); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritdoc} |
100
|
|
|
*/ |
101
|
|
|
public function getAlias() |
102
|
|
|
{ |
103
|
|
|
return 'nvbooster_assets'; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|