From f821130c3a4a22efd491aaad962cc84a82dde56a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 25 Nov 2014 17:04:15 +0100 Subject: [PATCH] [ticket/12632] Add twig.debug and twig.auto_reload in config.yml PHPBB3-13206 PHPBB3-12632 --- phpBB/config/default/container/services_twig.yml | 1 + phpBB/config/development/config.yml | 2 ++ .../phpbb/di/extension/container_configuration.php | 2 ++ phpBB/phpbb/di/extension/core.php | 14 ++++++++++++++ phpBB/phpbb/template/twig/environment.php | 2 +- .../fixtures/config/test/container/environment.yml | 11 +++++++++++ .../other_config/test/container/environment.yml | 11 +++++++++++ 7 files changed, 42 insertions(+), 1 deletion(-) diff --git a/phpBB/config/default/container/services_twig.yml b/phpBB/config/default/container/services_twig.yml index 6b54311f41..6214adfac6 100644 --- a/phpBB/config/default/container/services_twig.yml +++ b/phpBB/config/default/container/services_twig.yml @@ -11,6 +11,7 @@ services: - %core.template.cache_path% - @ext.manager - @template.twig.loader + - [] template.twig.lexer: class: phpbb\template\twig\lexer diff --git a/phpBB/config/development/config.yml b/phpBB/config/development/config.yml index f451eebe13..93ae07fb3f 100644 --- a/phpBB/config/development/config.yml +++ b/phpBB/config/development/config.yml @@ -5,4 +5,6 @@ core: require_dev_dependencies: true twig: + debug: true + auto_reload: true enable_debug_extension: true diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php index ee58ec2b74..4cc7c7c0d1 100644 --- a/phpBB/phpbb/di/extension/container_configuration.php +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -34,6 +34,8 @@ class container_configuration implements ConfigurationInterface ->arrayNode('twig') ->addDefaultsIfNotSet() ->children() + ->booleanNode('debug')->defaultValue(null)->end() + ->booleanNode('auto_reload')->defaultValue(null)->end() ->booleanNode('enable_debug_extension')->defaultValue(false)->end() ->end() ->end() diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index c71dc61280..c9e2d4dc5b 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -69,6 +69,20 @@ class core extends Extension } } + // Set the Twig options if defined in the environment + $definition = $container->getDefinition('template.twig.environment'); + $twig_environment_options = $definition->getArgument(6); + if ($config['twig']['debug']) + { + $twig_environment_options['debug'] = true; + } + if ($config['twig']['auto_reload']) + { + $twig_environment_options['auto_reload'] = true; + } + // Replace the 6th argument, the options passed to the environment + $definition->replaceArgument(6, $twig_environment_options); + if ($config['twig']['enable_debug_extension']) { $definition = $container->getDefinition('template.twig.extensions.debug'); diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 0ba7a265e4..fcd0566b6e 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -60,7 +60,7 @@ class environment extends \Twig_Environment $options = array_merge(array( 'cache' => (defined('IN_INSTALL')) ? false : $cache_path, - 'debug' => defined('DEBUG'), + 'debug' => false, 'auto_reload' => (bool) $this->phpbb_config['load_tplcompile'], 'autoescape' => false, ), $options); diff --git a/tests/di/fixtures/config/test/container/environment.yml b/tests/di/fixtures/config/test/container/environment.yml index f2a22ae109..0873078844 100644 --- a/tests/di/fixtures/config/test/container/environment.yml +++ b/tests/di/fixtures/config/test/container/environment.yml @@ -12,3 +12,14 @@ services: dispatcher: class: phpbb\db\driver\container_mock + + template.twig.environment: + class: Exception + arguments: + - ~ + - ~ + - ~ + - ~ + - ~ + - ~ + - [] diff --git a/tests/di/fixtures/other_config/test/container/environment.yml b/tests/di/fixtures/other_config/test/container/environment.yml index c299bfc648..2aa29db2eb 100644 --- a/tests/di/fixtures/other_config/test/container/environment.yml +++ b/tests/di/fixtures/other_config/test/container/environment.yml @@ -12,3 +12,14 @@ services: dispatcher: class: phpbb\db\driver\container_mock + + template.twig.environment: + class: Exception + arguments: + - ~ + - ~ + - ~ + - ~ + - ~ + - ~ + - []