|
@@ -5,6 +5,7 @@ namespace Symfony\Bundle\TwigBundle\DependencyInjection;
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
+use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
|
|
/*
|
|
|
* This file is part of the Symfony framework.
|
|
@@ -44,6 +45,20 @@ class TwigExtension extends Extension
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // globals
|
|
|
+ $def = $container->getDefinition('twig');
|
|
|
+ $globals = $this->fixConfig($config, 'global');
|
|
|
+ if (isset($globals[0])) {
|
|
|
+ foreach ($globals as $global) {
|
|
|
+ $def->addMethodCall('addGlobal', array($global['key'], new Reference($global['id'])));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ foreach ($globals as $key => $id) {
|
|
|
+ $def->addMethodCall('addGlobal', array($key, new Reference($id)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ unset($config['globals'], $config['global']);
|
|
|
+
|
|
|
// convert - to _
|
|
|
foreach ($config as $key => $value) {
|
|
|
$config[str_replace('-', '_', $key)] = $value;
|
|
@@ -71,4 +86,21 @@ class TwigExtension extends Extension
|
|
|
{
|
|
|
return 'twig';
|
|
|
}
|
|
|
+
|
|
|
+ protected function fixConfig($config, $key)
|
|
|
+ {
|
|
|
+ $values = array();
|
|
|
+ if (isset($config[$key.'s'])) {
|
|
|
+ $values = $config[$key.'s'];
|
|
|
+ } elseif (isset($config[$key])) {
|
|
|
+ if (is_string($config[$key]) || !is_int(key($config[$key]))) {
|
|
|
+ // only one
|
|
|
+ $values = array($config[$key]);
|
|
|
+ } else {
|
|
|
+ $values = $config[$key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $values;
|
|
|
+ }
|
|
|
}
|