|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Bundle\TwigBundle\DependencyInjection; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Config\FileLocator; |
|
|
15 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
16 |
use Symfony\Component\DependencyInjection\Reference; |
|
|
17 |
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
|
18 |
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
|
19 |
|
|
|
20 |
/** |
|
|
21 |
* TwigExtension. |
|
|
22 |
* |
|
|
23 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
24 |
* @author Jeremy Mikola <jmikola@gmail.com> |
|
|
25 |
*/ |
|
|
26 |
class TwigExtension extends Extension |
|
|
27 |
{ |
|
|
28 |
/** |
|
|
29 |
* Responds to the twig configuration parameter. |
|
|
30 |
* |
|
|
31 |
* @param array $configs |
|
|
32 |
* @param ContainerBuilder $container |
|
|
33 |
*/ |
|
|
34 |
public function load(array $configs, ContainerBuilder $container) |
|
|
35 |
{ |
|
|
36 |
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
|
37 |
$loader->load('twig.xml'); |
|
|
38 |
|
|
|
39 |
$configuration = new Configuration(); |
|
|
40 |
$config = $this->processConfiguration($configuration, $configs); |
|
|
41 |
|
|
|
42 |
$container->setParameter('twig.exception_listener.controller', $config['exception_controller']); |
|
|
43 |
|
|
|
44 |
$container->setParameter('twig.form.resources', $config['form']['resources']); |
|
|
45 |
$container->getDefinition('twig.loader')->addMethodCall('addPath', array(__DIR__.'/../../../Bridge/Twig/Resources/views/Form')); |
|
|
46 |
|
|
|
47 |
if (!empty($config['globals'])) { |
|
|
48 |
$def = $container->getDefinition('twig'); |
|
|
49 |
foreach ($config['globals'] as $key => $global) { |
|
|
50 |
if (isset($global['type']) && 'service' === $global['type']) { |
|
|
51 |
$def->addMethodCall('addGlobal', array($key, new Reference($global['id']))); |
|
|
52 |
} else { |
|
|
53 |
$def->addMethodCall('addGlobal', array($key, $global['value'])); |
|
|
54 |
} |
|
|
55 |
} |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
unset( |
|
|
59 |
$config['form'], |
|
|
60 |
$config['globals'], |
|
|
61 |
$config['extensions'] |
|
|
62 |
); |
|
|
63 |
|
|
|
64 |
$container->setParameter('twig.options', $config); |
|
|
65 |
|
|
|
66 |
$this->addClassesToCompile(array( |
|
|
67 |
'Twig_Environment', |
|
|
68 |
'Twig_ExtensionInterface', |
|
|
69 |
'Twig_Extension', |
|
|
70 |
'Twig_Extension_Core', |
|
|
71 |
'Twig_Extension_Escaper', |
|
|
72 |
'Twig_Extension_Optimizer', |
|
|
73 |
'Twig_LoaderInterface', |
|
|
74 |
'Twig_Markup', |
|
|
75 |
'Twig_TemplateInterface', |
|
|
76 |
'Twig_Template', |
|
|
77 |
)); |
|
|
78 |
} |
|
|
79 |
|
|
|
80 |
/** |
|
|
81 |
* Returns the base path for the XSD files. |
|
|
82 |
* |
|
|
83 |
* @return string The XSD base path |
|
|
84 |
*/ |
|
|
85 |
public function getXsdValidationBasePath() |
|
|
86 |
{ |
|
|
87 |
return __DIR__.'/../Resources/config/schema'; |
|
|
88 |
} |
|
|
89 |
|
|
|
90 |
public function getNamespace() |
|
|
91 |
{ |
|
|
92 |
return 'http://symfony.com/schema/dic/twig'; |
|
|
93 |
} |
|
|
94 |
} |