1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hshn\AngularBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
10
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
11
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
12
|
|
|
|
13
|
|
|
class HshnAngularExtension 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\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
24
|
|
|
|
25
|
|
|
if (isset($config['template_cache'])) { |
26
|
|
|
$this->loadTemplateCache($container, $loader, $config['template_cache']); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if (isset($config['assetic'])) { |
30
|
|
|
$moduleNames = isset($config['template_cache']) ? array_keys($config['template_cache']['modules']) : array(); |
31
|
|
|
|
32
|
|
|
$this->loadAssetic($container, $loader, $config['assetic'], $moduleNames); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param ContainerBuilder $container |
38
|
|
|
* @param LoaderInterface $loader |
39
|
|
|
* @param array $config |
40
|
|
|
*/ |
41
|
|
|
private function loadTemplateCache(ContainerBuilder $container, LoaderInterface $loader, array $config) |
42
|
|
|
{ |
43
|
|
|
$loader->load('template_cache.yml'); |
44
|
|
|
|
45
|
|
|
$container |
46
|
|
|
->getDefinition('hshn_angular.command.dump_template_cache') |
47
|
|
|
->replaceArgument(1, $config['dump_path']); |
48
|
|
|
|
49
|
|
|
$this->loadModuleInformation($container, $config['modules']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param ContainerBuilder $container |
54
|
|
|
* @param array $modules |
55
|
|
|
*/ |
56
|
|
|
private function loadModuleInformation(ContainerBuilder $container, array $modules) |
57
|
|
|
{ |
58
|
|
|
$manager = $container->getDefinition('hshn_angular.template_cache.manager'); |
59
|
|
|
|
60
|
|
|
foreach ($modules as $name => $module) { |
61
|
|
|
$configuration = new DefinitionDecorator('hshn_angular.template_cache.configuration'); |
62
|
|
|
$configuration |
63
|
|
|
->addMethodCall('setName', array($module['name'] ?: $name)) |
64
|
|
|
->addMethodCall('setCreate', array($module['create'])) |
65
|
|
|
->addMethodCall('setTargets', array($module['targets'])); |
66
|
|
|
|
67
|
|
|
$container->setDefinition($id = sprintf('hshn_angular.template_cache.configuration.%s', $name), $configuration); |
68
|
|
|
$manager->addMethodCall('addModule', array($name, new Reference($id))); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param ContainerBuilder $container |
74
|
|
|
* @param LoaderInterface $loader |
75
|
|
|
* @param array $config |
76
|
|
|
* @param array $moduleNames |
77
|
|
|
*/ |
78
|
|
|
private function loadAssetic(ContainerBuilder $container, LoaderInterface $loader, array $config, array $moduleNames) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$loader->load('assetic.yml'); |
81
|
|
|
|
82
|
|
|
foreach ($moduleNames as $moduleName) { |
83
|
|
|
$asset = new DefinitionDecorator('hshn_angular.asset.template_cache'); |
84
|
|
|
$asset->replaceArgument(2, new Reference(sprintf('hshn_angular.template_cache.configuration.%s', $moduleName))); |
85
|
|
|
$asset->addMethodCall('setTargetPath', array(sprintf('js/ng_template_cache/%s.js', $moduleName))); |
86
|
|
|
$asset->addTag('assetic.asset', array('alias' => 'ng_template_cache_' . $moduleName)); |
87
|
|
|
|
88
|
|
|
$container->setDefinition(sprintf('hshn_angular.asset.template_cache.%s', $moduleName), $asset); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.