diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
index 33caa7317d..8afd80a252 100644
--- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
+++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
@@ -50,11 +50,21 @@ class TwigExtension extends Extension
$globals = $this->fixConfig($config, 'global');
if (isset($globals[0])) {
foreach ($globals as $global) {
- $def->addMethodCall('addGlobal', array($global['key'], new Reference($global['id'])));
+ if (isset($global['type']) && 'service' === $global['type']) {
+ $def->addMethodCall('addGlobal', array($global['key'], new Reference($global['id'])));
+ } elseif (isset($global['value'])) {
+ $def->addMethodCall('addGlobal', array($global['key'], $global['value']));
+ } else {
+ throw new \InvalidArgumentException(sprintf('Unable to understand global configuration (%s).', var_export($global, true)));
+ }
}
} else {
- foreach ($globals as $key => $id) {
- $def->addMethodCall('addGlobal', array($key, new Reference($id)));
+ foreach ($globals as $key => $value) {
+ if ('@' === substr($value, 0, 1)) {
+ $def->addMethodCall('addGlobal', array($key, new Reference(substr($value, 1))));
+ } else {
+ $def->addMethodCall('addGlobal', array($key, $value));
+ }
}
}
unset($config['globals'], $config['global']);
diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd b/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd
index 2df43123c4..9cbbff1c87 100644
--- a/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd
+++ b/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd
@@ -10,7 +10,7 @@
-
+
@@ -29,8 +29,9 @@
-
-
+
+
+
diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
index d4e81b6b50..7f0e785005 100644
--- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
+++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
@@ -14,6 +14,7 @@ namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection;
use Symfony\Bundle\TwigBundle\Tests\TestCase;
use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
class TwigExtensionTest extends TestCase
{
@@ -36,18 +37,28 @@ class TwigExtensionTest extends TestCase
// XML
$container = new ContainerBuilder();
$loader = new TwigExtension();
- $loader->configLoad(array('global' => array(array('key' => 'foo', 'id' => 'bar'))), $container);
+ $loader->configLoad(array('global' => array(
+ array('key' => 'foo', 'type' => 'service', 'id' => 'bar'),
+ array('key' => 'pi', 'value' => 3.14),
+ )), $container);
$config = $container->getDefinition('twig')->getMethodCalls();
$this->assertEquals('foo', $config[0][1][0]);
- $this->assertEquals('bar', (string) $config[0][1][1]);
+ $this->assertEquals(new Reference('bar'), $config[0][1][1]);
+ $this->assertEquals('pi', $config[1][1][0]);
+ $this->assertEquals(3.14, $config[1][1][1]);
// YAML, PHP
$container = new ContainerBuilder();
$loader = new TwigExtension();
- $loader->configLoad(array('globals' => array('foo' => 'bar')), $container);
+ $loader->configLoad(array('globals' => array(
+ 'foo' => '@bar',
+ 'pi' => 3.14,
+ )), $container);
$config = $container->getDefinition('twig')->getMethodCalls();
$this->assertEquals('foo', $config[0][1][0]);
- $this->assertEquals('bar', (string) $config[0][1][1]);
+ $this->assertEquals(new Reference('bar'), $config[0][1][1]);
+ $this->assertEquals('pi', $config[1][1][0]);
+ $this->assertEquals(3.14, $config[1][1][1]);
}
public function testConfigExtensions()