|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Strontium\PjaxBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* {@inheritdoc} |
|
14
|
|
|
*/ |
|
15
|
|
|
class StrontiumPjaxExtension extends Extension implements PrependExtensionInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
21
|
|
|
{ |
|
22
|
|
|
$config = $this->processConfiguration(new Configuration(), $configs); |
|
23
|
|
|
|
|
24
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
25
|
|
|
$loader->load('services.yml'); |
|
26
|
|
|
|
|
27
|
|
|
$container |
|
28
|
|
|
->getDefinition('pjax.twig.extension') |
|
29
|
|
|
->addMethodCall('setSections', [$config['sections']]); |
|
30
|
|
|
|
|
31
|
|
|
if ($config['add_content_version'] === true && $config['version_generator']) { |
|
32
|
|
|
$container |
|
33
|
|
|
->getDefinition('pjax.helper') |
|
34
|
|
|
->addMethodCall('setVersionGenerator', [new Reference($config['version_generator'])]); |
|
35
|
|
|
|
|
36
|
|
|
$container |
|
37
|
|
|
->getDefinition('pjax.kernel.event_listener.response') |
|
38
|
|
|
->addTag('kernel.event_listener', [ |
|
39
|
|
|
'event' => 'kernel.response', |
|
40
|
|
|
'method' => 'addPjaxVersion' |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
if ($config['menu']) { |
|
44
|
|
|
$loader->load('menu.yml'); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function prepend(ContainerBuilder $container) |
|
52
|
|
|
{ |
|
53
|
|
|
$input = [ |
|
54
|
|
|
'@StrontiumPjaxBundle/Resources/public/js/dom-initializer.js', |
|
55
|
|
|
'@StrontiumPjaxBundle/Resources/public/js/pjax.js', |
|
56
|
|
|
'@StrontiumPjaxBundle/Resources/public/js/modal.js', |
|
57
|
|
|
'@StrontiumPjaxBundle/Resources/public/js/flash.js', |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
$configs = $container->getExtensionConfig($this->getAlias()); |
|
61
|
|
|
$config = $this->processConfiguration(new Configuration(), $configs); |
|
62
|
|
|
if ($config['menu']) { |
|
63
|
|
|
$input[] = '@StrontiumPjaxBundle/Resources/public/js/menu.js'; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$container->prependExtensionConfig('assetic', [ |
|
68
|
|
|
'assets' => [ |
|
69
|
|
|
'pjax' => [ |
|
70
|
|
|
'input' => $input, |
|
71
|
|
|
] |
|
72
|
|
|
] |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|