diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php
index 9fbfd65950a53..711743a5af634 100644
--- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php
+++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php
@@ -27,8 +27,14 @@ public function process(ContainerBuilder $container)
return;
}
- // register the exception controller only if Twig is enabled
- if ($container->hasParameter('templating.engines')) {
+ if (!interface_exists('Symfony\Component\Templating\TemplateReferenceInterface')) {
+ $container->removeDefinition('twig.controller.exception');
+ }
+
+ // register the exception controller only if Twig is enabled and required dependencies do exist
+ if (!class_exists('Symfony\Component\Debug\Exception\FlattenException') || !interface_exists('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
+ $container->removeDefinition('twig.exception_listener');
+ } elseif ($container->hasParameter('templating.engines')) {
$engines = $container->getParameter('templating.engines');
if (!in_array('twig', $engines)) {
$container->removeDefinition('twig.exception_listener');
diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php
index d09de2d615c0a..d619de0d81cec 100644
--- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php
+++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php
@@ -23,6 +23,25 @@ class ExtensionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
+ if (!class_exists('Symfony\Component\Asset\Packages')) {
+ $container->removeDefinition('twig.extension.assets');
+ }
+
+ if (!class_exists('Symfony\Component\ExpressionLanguage\Expression')) {
+ $container->removeDefinition('twig.extension.expression');
+ }
+
+ if (!interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
+ $container->removeDefinition('twig.extension.routing');
+ }
+ if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
+ $container->removeDefinition('twig.extension.trans');
+ }
+
+ if (!class_exists('Symfony\Component\Yaml\Yaml')) {
+ $container->removeDefinition('twig.extension.yaml');
+ }
+
if ($container->has('form.extension')) {
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
index 7b97e120baa4b..5eb163c8869bb 100644
--- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
+++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
@@ -36,6 +36,18 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('twig.xml');
+ if (class_exists('Symfony\Component\Form\Form')) {
+ $loader->load('form.xml');
+ }
+
+ if (interface_exists('Symfony\Component\Templating\EngineInterface')) {
+ $loader->load('templating.xml');
+ }
+
+ if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
+ $container->removeDefinition('twig.translation.extractor');
+ }
+
foreach ($configs as $key => $config) {
if (isset($config['globals'])) {
foreach ($config['globals'] as $name => $value) {
diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/form.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/form.xml
new file mode 100644
index 0000000000000..0703f0f57774a
--- /dev/null
+++ b/src/Symfony/Bundle/TwigBundle/Resources/config/form.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+ %twig.form.resources%
+
+
+
+
+
+
+
+
diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/templating.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/templating.xml
new file mode 100644
index 0000000000000..5a39c95018c0b
--- /dev/null
+++ b/src/Symfony/Bundle/TwigBundle/Resources/config/templating.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
index f2c2a4cee007c..c08be1f0399ed 100644
--- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
+++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
@@ -55,22 +55,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -130,21 +116,8 @@
-
-
-
-
-
- %twig.form.resources%
-
-
-
-
-
-
-