From 81e291af29cf9f38502d6cff056c9f4c01e39531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Sat, 23 Feb 2019 15:59:41 +0100 Subject: [PATCH 1/8] Moves default overriden bnudle path registration to a CompilerPass --- .../DefaultOverridenBundlePathPass.php | 65 +++++++++++++++++++ .../DependencyInjection/TwigExtension.php | 14 ---- src/Symfony/Bundle/TwigBundle/TwigBundle.php | 2 + 3 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverridenBundlePathPass.php diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverridenBundlePathPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverridenBundlePathPass.php new file mode 100644 index 0000000000000..531d779506228 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverridenBundlePathPass.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler; + +use Symfony\Component\Config\Resource\FileExistenceResource; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** + * Registers the default overriding bundles paths. + */ +class DefaultOverridenBundlePathPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + $twigLoaderFilesystemId = $container->getAlias('twig.loader')->__toString(); + + if (false === $container->hasDefinition($twigLoaderFilesystemId)) { + return; + } + + $twigLoaderFilesystemDefinition = $container->getDefinition($twigLoaderFilesystemId); + $twigDefaultPath = $container->getParameter('twig.default_path'); + + foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) { + $defaultOverrideBundlePath = $container->getParameterBag()->resolveValue($twigDefaultPath).'/bundles/'.$name; + + if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views')) { + @trigger_error(sprintf('Templates directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultOverrideBundlePath), E_USER_DEPRECATED); + + $twigLoaderFilesystemDefinition->addMethodCall( + 'prependPath', + [$dir, $this->normalizeBundleName($name)] + ); + } + $container->addResource(new FileExistenceResource($dir)); + + if (file_exists($defaultOverrideBundlePath)) { + $twigLoaderFilesystemDefinition->addMethodCall( + 'prependPath', + [$defaultOverrideBundlePath, $this->normalizeBundleName($name)] + ); + } + $container->addResource(new FileExistenceResource($defaultOverrideBundlePath)); + } + } + + private function normalizeBundleName($name) + { + if ('Bundle' === substr($name, -6)) { + $name = substr($name, 0, -6); + } + + return $name; + } +} diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index a9db7bf6a8612..4d30f559e3f38 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -169,20 +169,6 @@ private function getBundleTemplatePaths(ContainerBuilder $container, array $conf { $bundleHierarchy = []; foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) { - $defaultOverrideBundlePath = $container->getParameterBag()->resolveValue($config['default_path']).'/bundles/'.$name; - - if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views')) { - @trigger_error(sprintf('Templates directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultOverrideBundlePath), E_USER_DEPRECATED); - - $bundleHierarchy[$name][] = $dir; - } - $container->addResource(new FileExistenceResource($dir)); - - if (file_exists($defaultOverrideBundlePath)) { - $bundleHierarchy[$name][] = $defaultOverrideBundlePath; - } - $container->addResource(new FileExistenceResource($defaultOverrideBundlePath)); - if (file_exists($dir = $bundle['path'].'/Resources/views')) { $bundleHierarchy[$name][] = $dir; } diff --git a/src/Symfony/Bundle/TwigBundle/TwigBundle.php b/src/Symfony/Bundle/TwigBundle/TwigBundle.php index bd766c15219e7..e595f259161ce 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigBundle.php +++ b/src/Symfony/Bundle/TwigBundle/TwigBundle.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\TwigBundle; +use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\DefaultOverridenBundlePathPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass; @@ -37,6 +38,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new TwigLoaderPass()); $container->addCompilerPass(new ExceptionListenerPass()); $container->addCompilerPass(new RuntimeLoaderPass(), PassConfig::TYPE_BEFORE_REMOVING); + $container->addCompilerPass(new DefaultOverridenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); } public function registerCommands(Application $application) From c9b9db2c2522162bd0382d00116571ac8051abf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Sat, 23 Feb 2019 21:48:57 +0100 Subject: [PATCH 2/8] Fix typo in class name --- ...BundlePathPass.php => DefaultOverriddenBundlePathPass.php} | 2 +- src/Symfony/Bundle/TwigBundle/TwigBundle.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/{DefaultOverridenBundlePathPass.php => DefaultOverriddenBundlePathPass.php} (96%) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverridenBundlePathPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php similarity index 96% rename from src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverridenBundlePathPass.php rename to src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php index 531d779506228..afb54fd58fd64 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverridenBundlePathPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php @@ -18,7 +18,7 @@ /** * Registers the default overriding bundles paths. */ -class DefaultOverridenBundlePathPass implements CompilerPassInterface +final class DefaultOverriddenBundlePathPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { diff --git a/src/Symfony/Bundle/TwigBundle/TwigBundle.php b/src/Symfony/Bundle/TwigBundle/TwigBundle.php index e595f259161ce..e3d0746572ff5 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigBundle.php +++ b/src/Symfony/Bundle/TwigBundle/TwigBundle.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\TwigBundle; -use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\DefaultOverridenBundlePathPass; +use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\DefaultOverriddenBundlePathPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass; @@ -38,7 +38,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new TwigLoaderPass()); $container->addCompilerPass(new ExceptionListenerPass()); $container->addCompilerPass(new RuntimeLoaderPass(), PassConfig::TYPE_BEFORE_REMOVING); - $container->addCompilerPass(new DefaultOverridenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); + $container->addCompilerPass(new DefaultOverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); } public function registerCommands(Application $application) From f3873ae443458ad544108ce3e225aaf293086074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Sat, 23 Feb 2019 23:09:39 +0100 Subject: [PATCH 3/8] Fix existing tests --- .../Tests/DependencyInjection/TwigExtensionTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 0a227930bd1ef..ac32b5e8f63c7 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -193,7 +193,6 @@ public function testTwigLoaderPaths($format) ['namespaced_path1', 'namespace1'], ['namespaced_path2', 'namespace2'], ['namespaced_path3', 'namespace3'], - [__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'], [realpath(__DIR__.'/../..').'/Resources/views', 'Twig'], [realpath(__DIR__.'/../..').'/Resources/views', '!Twig'], [__DIR__.'/Fixtures/templates'], @@ -203,7 +202,6 @@ public function testTwigLoaderPaths($format) /** * @group legacy * @dataProvider getFormats - * @expectedDeprecation Templates directory "%s/Resources/TwigBundle/views" is deprecated since Symfony 4.2, use "%s/templates/bundles/TwigBundle" instead. * @expectedDeprecation Templates directory "%s/Resources/views" is deprecated since Symfony 4.2, use "%s/templates" instead. */ public function testLegacyTwigLoaderPaths($format) @@ -228,8 +226,6 @@ public function testLegacyTwigLoaderPaths($format) ['namespaced_path1', 'namespace1'], ['namespaced_path2', 'namespace2'], ['namespaced_path3', 'namespace3'], - [__DIR__.'/../Fixtures/templates/Resources/TwigBundle/views', 'Twig'], - [__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'], [realpath(__DIR__.'/../..').'/Resources/views', 'Twig'], [realpath(__DIR__.'/../..').'/Resources/views', '!Twig'], [__DIR__.'/../Fixtures/templates/Resources/views'], From 15b1e0a5112823f253cae0dd371c62323031582e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Sat, 23 Feb 2019 23:55:05 +0100 Subject: [PATCH 4/8] Add tests for default overridden bundle paths --- .../DefaultOverriddenBundlePathPass.php | 2 +- .../DependencyInjection/TwigExtensionTest.php | 36 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php index afb54fd58fd64..ee48f3e64d1e5 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php @@ -22,7 +22,7 @@ final class DefaultOverriddenBundlePathPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { - $twigLoaderFilesystemId = $container->getAlias('twig.loader')->__toString(); + $twigLoaderFilesystemId = 'twig.loader.native_filesystem'; if (false === $container->hasDefinition($twigLoaderFilesystemId)) { return; diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index ac32b5e8f63c7..8fed8f0171ce1 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection; +use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\DefaultOverriddenBundlePathPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass; use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Symfony\Bundle\TwigBundle\Tests\TestCase; @@ -177,13 +178,20 @@ public function testTwigLoaderPaths($format) $container->registerExtension(new TwigExtension()); $this->loadFromFile($container, 'full', $format); $this->loadFromFile($container, 'extra', $format); + $container->addCompilerPass(new DefaultOverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); $this->compileContainer($container); $def = $container->getDefinition('twig.loader.native_filesystem'); - $paths = []; + $addedPaths = []; foreach ($def->getMethodCalls() as $call) { if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) { - $paths[] = $call[1]; + $addedPaths[] = $call[1]; + } + } + $prependedPaths = []; + foreach ($def->getMethodCalls() as $call) { + if ('prependPath' === $call[0] && false === strpos($call[1][0], 'Form')) { + $prependedPaths[] = $call[1]; } } @@ -196,12 +204,17 @@ public function testTwigLoaderPaths($format) [realpath(__DIR__.'/../..').'/Resources/views', 'Twig'], [realpath(__DIR__.'/../..').'/Resources/views', '!Twig'], [__DIR__.'/Fixtures/templates'], - ], $paths); + ], $addedPaths); + $this->assertEquals([ + [__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'], + ], $prependedPaths); } /** * @group legacy * @dataProvider getFormats + * @dataProvider getFormats + * @expectedDeprecation Templates directory "%s/Resources/TwigBundle/views" is deprecated since Symfony 4.2, use "%s/templates/bundles/TwigBundle" instead. * @expectedDeprecation Templates directory "%s/Resources/views" is deprecated since Symfony 4.2, use "%s/templates" instead. */ public function testLegacyTwigLoaderPaths($format) @@ -210,13 +223,20 @@ public function testLegacyTwigLoaderPaths($format) $container->registerExtension(new TwigExtension()); $this->loadFromFile($container, 'full', $format); $this->loadFromFile($container, 'extra', $format); + $container->addCompilerPass(new DefaultOverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); $this->compileContainer($container); $def = $container->getDefinition('twig.loader.native_filesystem'); - $paths = []; + $addedPaths = []; foreach ($def->getMethodCalls() as $call) { if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) { - $paths[] = $call[1]; + $addedPaths[] = $call[1]; + } + } + $prependedPaths = []; + foreach ($def->getMethodCalls() as $call) { + if ('prependPath' === $call[0] && false === strpos($call[1][0], 'Form')) { + $prependedPaths[] = $call[1]; } } @@ -230,7 +250,11 @@ public function testLegacyTwigLoaderPaths($format) [realpath(__DIR__.'/../..').'/Resources/views', '!Twig'], [__DIR__.'/../Fixtures/templates/Resources/views'], [__DIR__.'/Fixtures/templates'], - ], $paths); + ], $addedPaths); + $this->assertEquals([ + [__DIR__.'/../Fixtures/templates/Resources/TwigBundle/views', 'Twig'], + [__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'], + ], $prependedPaths); } public function getFormats() From 9a8a3794834440e869c87f749ab937aae4e078e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Sun, 24 Feb 2019 00:08:13 +0100 Subject: [PATCH 5/8] Fix expectedDeprecation order in test --- .../TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 8fed8f0171ce1..725a34a5578ab 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -214,8 +214,8 @@ public function testTwigLoaderPaths($format) * @group legacy * @dataProvider getFormats * @dataProvider getFormats - * @expectedDeprecation Templates directory "%s/Resources/TwigBundle/views" is deprecated since Symfony 4.2, use "%s/templates/bundles/TwigBundle" instead. * @expectedDeprecation Templates directory "%s/Resources/views" is deprecated since Symfony 4.2, use "%s/templates" instead. + * @expectedDeprecation Templates directory "%s/Resources/TwigBundle/views" is deprecated since Symfony 4.2, use "%s/templates/bundles/TwigBundle" instead. */ public function testLegacyTwigLoaderPaths($format) { From 14b5dc89afd31b8126317a6ff87e0e071c6d356f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Mon, 25 Feb 2019 21:18:21 +0100 Subject: [PATCH 6/8] Move twig user-configured paths definition to OverriddenBundlePathPass --- ...thPass.php => OverriddenBundlePathPass.php} | 18 ++++++++++++++---- .../DependencyInjection/TwigExtension.php | 8 +++++++- .../DependencyInjection/TwigExtensionTest.php | 18 +++++++++--------- src/Symfony/Bundle/TwigBundle/TwigBundle.php | 4 ++-- 4 files changed, 32 insertions(+), 16 deletions(-) rename src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/{DefaultOverriddenBundlePathPass.php => OverriddenBundlePathPass.php} (79%) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/OverriddenBundlePathPass.php similarity index 79% rename from src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php rename to src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/OverriddenBundlePathPass.php index ee48f3e64d1e5..0aeeac38b5544 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/DefaultOverriddenBundlePathPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/OverriddenBundlePathPass.php @@ -16,21 +16,21 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * Registers the default overriding bundles paths. + * Registers the default and user-configured overriding bundles paths. */ -final class DefaultOverriddenBundlePathPass implements CompilerPassInterface +final class OverriddenBundlePathPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { $twigLoaderFilesystemId = 'twig.loader.native_filesystem'; - if (false === $container->hasDefinition($twigLoaderFilesystemId)) { return; } - $twigLoaderFilesystemDefinition = $container->getDefinition($twigLoaderFilesystemId); + $twigDefaultPath = $container->getParameter('twig.default_path'); + // Adds Twig default_path relative overriden path on top foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) { $defaultOverrideBundlePath = $container->getParameterBag()->resolveValue($twigDefaultPath).'/bundles/'.$name; @@ -52,6 +52,16 @@ public function process(ContainerBuilder $container) } $container->addResource(new FileExistenceResource($defaultOverrideBundlePath)); } + + // Adds user-configured namespaced paths + foreach ($container->getParameter('twig.namespaced_user_configured_paths') as $namespace => $paths) { + foreach ($paths as $path) { + $twigLoaderFilesystemDefinition->addMethodCall( + 'prependPath', + [$path, $namespace] + ); + } + } } private function normalizeBundleName($name) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 4d30f559e3f38..f3ed3252b862a 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -91,13 +91,19 @@ public function load(array $configs, ContainerBuilder $container) } // register user-configured paths + $namespacedUserConfiguredPaths = []; foreach ($config['paths'] as $path => $namespace) { if (!$namespace) { $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path]); } else { - $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path, $namespace]); + if (isset($namespacedUserConfiguredPaths[$namespace])) { + array_unshift($namespacedUserConfiguredPaths[$namespace], $path); + } else { + $namespacedUserConfiguredPaths[$namespace] = [$path]; + } } } + $container->setParameter('twig.namespaced_user_configured_paths', $namespacedUserConfiguredPaths); // paths are modified in ExtensionPass if forms are enabled $container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 725a34a5578ab..da71228da6241 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection; -use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\DefaultOverriddenBundlePathPass; +use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\OverriddenBundlePathPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass; use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Symfony\Bundle\TwigBundle\Tests\TestCase; @@ -178,7 +178,7 @@ public function testTwigLoaderPaths($format) $container->registerExtension(new TwigExtension()); $this->loadFromFile($container, 'full', $format); $this->loadFromFile($container, 'extra', $format); - $container->addCompilerPass(new DefaultOverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); + $container->addCompilerPass(new OverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); $this->compileContainer($container); $def = $container->getDefinition('twig.loader.native_filesystem'); @@ -198,15 +198,15 @@ public function testTwigLoaderPaths($format) $this->assertEquals([ ['path1'], ['path2'], - ['namespaced_path1', 'namespace1'], - ['namespaced_path2', 'namespace2'], - ['namespaced_path3', 'namespace3'], [realpath(__DIR__.'/../..').'/Resources/views', 'Twig'], [realpath(__DIR__.'/../..').'/Resources/views', '!Twig'], [__DIR__.'/Fixtures/templates'], ], $addedPaths); $this->assertEquals([ [__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'], + ['namespaced_path1', 'namespace1'], + ['namespaced_path2', 'namespace2'], + ['namespaced_path3', 'namespace3'], ], $prependedPaths); } @@ -223,7 +223,7 @@ public function testLegacyTwigLoaderPaths($format) $container->registerExtension(new TwigExtension()); $this->loadFromFile($container, 'full', $format); $this->loadFromFile($container, 'extra', $format); - $container->addCompilerPass(new DefaultOverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); + $container->addCompilerPass(new OverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); $this->compileContainer($container); $def = $container->getDefinition('twig.loader.native_filesystem'); @@ -243,9 +243,6 @@ public function testLegacyTwigLoaderPaths($format) $this->assertEquals([ ['path1'], ['path2'], - ['namespaced_path1', 'namespace1'], - ['namespaced_path2', 'namespace2'], - ['namespaced_path3', 'namespace3'], [realpath(__DIR__.'/../..').'/Resources/views', 'Twig'], [realpath(__DIR__.'/../..').'/Resources/views', '!Twig'], [__DIR__.'/../Fixtures/templates/Resources/views'], @@ -254,6 +251,9 @@ public function testLegacyTwigLoaderPaths($format) $this->assertEquals([ [__DIR__.'/../Fixtures/templates/Resources/TwigBundle/views', 'Twig'], [__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'], + ['namespaced_path1', 'namespace1'], + ['namespaced_path2', 'namespace2'], + ['namespaced_path3', 'namespace3'], ], $prependedPaths); } diff --git a/src/Symfony/Bundle/TwigBundle/TwigBundle.php b/src/Symfony/Bundle/TwigBundle/TwigBundle.php index e3d0746572ff5..aeff6e3479e87 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigBundle.php +++ b/src/Symfony/Bundle/TwigBundle/TwigBundle.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\TwigBundle; -use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\DefaultOverriddenBundlePathPass; +use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\OverriddenBundlePathPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass; @@ -38,7 +38,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new TwigLoaderPass()); $container->addCompilerPass(new ExceptionListenerPass()); $container->addCompilerPass(new RuntimeLoaderPass(), PassConfig::TYPE_BEFORE_REMOVING); - $container->addCompilerPass(new DefaultOverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); + $container->addCompilerPass(new OverriddenBundlePathPass(), PassConfig::TYPE_BEFORE_REMOVING); } public function registerCommands(Application $application) From 49ede3f57eb7dd640b62be36e55d2240a1c8f310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Mon, 25 Feb 2019 21:23:05 +0100 Subject: [PATCH 7/8] Code style fix --- src/Symfony/Bundle/TwigBundle/TwigBundle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/TwigBundle.php b/src/Symfony/Bundle/TwigBundle/TwigBundle.php index aeff6e3479e87..785789cdfe3d0 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigBundle.php +++ b/src/Symfony/Bundle/TwigBundle/TwigBundle.php @@ -11,9 +11,9 @@ namespace Symfony\Bundle\TwigBundle; -use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\OverriddenBundlePathPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass; +use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\OverriddenBundlePathPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass; From 1b9124166f266ffb4cc1e6612a3ebbc253ae05dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Tue, 5 Mar 2019 09:32:53 +0100 Subject: [PATCH 8/8] Use type hinting --- .../DependencyInjection/Compiler/OverriddenBundlePathPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/OverriddenBundlePathPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/OverriddenBundlePathPass.php index 0aeeac38b5544..0199b2b95c8b6 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/OverriddenBundlePathPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/OverriddenBundlePathPass.php @@ -64,7 +64,7 @@ public function process(ContainerBuilder $container) } } - private function normalizeBundleName($name) + private function normalizeBundleName(string $name): string { if ('Bundle' === substr($name, -6)) { $name = substr($name, 0, -6);