From 4b6752bf3ec1e0df1c364030dd20c9853af0f5a8 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 28 May 2019 17:10:04 -0400 Subject: [PATCH] Removed capability to load Twig template from legacy directories --- .../Bridge/Twig/Command/DebugCommand.php | 34 +---------------- .../Twig/Tests/Command/DebugCommandTest.php | 26 ------------- src/Symfony/Bundle/TwigBundle/CHANGELOG.md | 1 + .../DependencyInjection/TwigExtension.php | 16 -------- .../DependencyInjection/TwigExtensionTest.php | 37 ------------------- .../TwigBundle/views/layout.html.twig | 1 - 6 files changed, 3 insertions(+), 112 deletions(-) delete mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/TwigBundle/views/layout.html.twig diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index e12fd9c04d..fa142d381e 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -38,15 +38,10 @@ class DebugCommand extends Command private $projectDir; private $bundlesMetadata; private $twigDefaultPath; - private $rootDir; private $filesystemLoaders; private $fileLinkFormatter; - /** - * @param FileLinkFormatter|null $fileLinkFormatter - * @param string|null $rootDir - */ - public function __construct(Environment $twig, string $projectDir = null, array $bundlesMetadata = [], string $twigDefaultPath = null, $fileLinkFormatter = null, $rootDir = null) + public function __construct(Environment $twig, string $projectDir = null, array $bundlesMetadata = [], string $twigDefaultPath = null, FileLinkFormatter $fileLinkFormatter = null) { parent::__construct(); @@ -54,16 +49,7 @@ class DebugCommand extends Command $this->projectDir = $projectDir; $this->bundlesMetadata = $bundlesMetadata; $this->twigDefaultPath = $twigDefaultPath; - - if (\is_string($fileLinkFormatter) || $rootDir instanceof FileLinkFormatter) { - @trigger_error(sprintf('Passing a string as "$fileLinkFormatter" 5th argument or an instance of FileLinkFormatter as "$rootDir" 6th argument of the "%s()" method is deprecated since Symfony 4.4, swap the variables position.', __METHOD__), E_USER_DEPRECATED); - - $this->rootDir = $fileLinkFormatter; - $this->fileLinkFormatter = $rootDir; - } else { - $this->fileLinkFormatter = $fileLinkFormatter; - $this->rootDir = $rootDir; - } + $this->fileLinkFormatter = $fileLinkFormatter; } protected function configure() @@ -397,22 +383,6 @@ EOF $alternatives = []; $bundleNames = []; - if ($this->rootDir && $this->projectDir) { - $folders = glob($this->rootDir.'/Resources/*/views', GLOB_ONLYDIR); - $relativePath = ltrim(substr($this->rootDir.\DIRECTORY_SEPARATOR.'Resources/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); - $bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) { - if (0 === strpos($absolutePath, $this->projectDir)) { - $name = basename(\dirname($absolutePath)); - $path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR); - $carry[$name] = $path; - - @trigger_error(sprintf('Loading Twig templates from the "%s" directory is deprecated since Symfony 4.2, use "%s" instead.', $absolutePath, $this->twigDefaultPath.'/bundles/'.$name), E_USER_DEPRECATED); - } - - return $carry; - }, $bundleNames); - } - if ($this->twigDefaultPath && $this->projectDir) { $folders = glob($this->twigDefaultPath.'/bundles/*', GLOB_ONLYDIR); $relativePath = ltrim(substr($this->twigDefaultPath.'/bundles/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); diff --git a/src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php b/src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php index 516dd75387..17760e0718 100644 --- a/src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php @@ -63,32 +63,6 @@ class DebugCommandTest extends TestCase $this->assertEquals($expected, json_decode($tester->getDisplay(true), true)); } - /** - * @group legacy - * @expectedDeprecation Loading Twig templates from the "%sResources/BarBundle/views" directory is deprecated since Symfony 4.2, use "%stemplates/bundles/BarBundle" instead. - */ - public function testDeprecationForWrongBundleOverridingInLegacyPath() - { - $bundleMetadata = [ - 'TwigBundle' => 'vendor/twig-bundle/', - 'WebProfilerBundle' => 'vendor/web-profiler-bundle/', - ]; - $defaultPath = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'templates'; - $rootDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'; - - $tester = $this->createCommandTester([], $bundleMetadata, $defaultPath, $rootDir); - $ret = $tester->execute(['--filter' => 'unknown', '--format' => 'json'], ['decorated' => false]); - - $expected = ['warnings' => [ - 'Path "Resources/BarBundle" not matching any bundle found', - 'Path "templates/bundles/UnknownBundle" not matching any bundle found', - 'Path "templates/bundles/WebProfileBundle" not matching any bundle found, did you mean "WebProfilerBundle"?', - ]]; - - $this->assertEquals(0, $ret, 'Returns 0 in case of success'); - $this->assertEquals($expected, json_decode($tester->getDisplay(true), true)); - } - /** * @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException * @expectedExceptionMessage Malformed namespaced template name "@foo" (expecting "@namespace/template_name"). diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index 7a9d02e29a..9f7ddd9fbe 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * updated default value for the `strict_variables` option to `%kernel.debug%` parameter + * removed support to load templates from the legacy directories `src/Resources/views/` and `src/Resources//views/` 4.2.0 ----- diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 8f8b65cf2e..d56dc154c7 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -120,15 +120,6 @@ class TwigExtension extends Extension } } - if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) { - if ($dir !== $defaultTwigPath) { - @trigger_error(sprintf('Loading Twig templates from the "%s" directory is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultTwigPath), E_USER_DEPRECATED); - } - - $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$dir]); - } - $container->addResource(new FileExistenceResource($dir)); - if (file_exists($defaultTwigPath)) { $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$defaultTwigPath]); } @@ -176,13 +167,6 @@ class TwigExtension extends Extension 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('Loading Twig templates for "%s" from the "%s" directory is deprecated since Symfony 4.2, use "%s" instead.', $name, $dir, $defaultOverrideBundlePath), E_USER_DEPRECATED); - - $bundleHierarchy[$name][] = $dir; - } - $container->addResource(new FileExistenceResource($dir)); - if (file_exists($defaultOverrideBundlePath)) { $bundleHierarchy[$name][] = $defaultOverrideBundlePath; } diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 7b3595e93c..bfff63ab21 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -197,43 +197,6 @@ class TwigExtensionTest extends TestCase ], $paths); } - /** - * @group legacy - * @dataProvider getFormats - * @expectedDeprecation Loading Twig templates for "TwigBundle" from the "%s/Resources/TwigBundle/views" directory is deprecated since Symfony 4.2, use "%s/templates/bundles/TwigBundle" instead. - * @expectedDeprecation Loading Twig templates from the "%s/Resources/views" directory is deprecated since Symfony 4.2, use "%s/templates" instead. - */ - public function testLegacyTwigLoaderPaths($format) - { - $container = $this->createContainer(__DIR__.'/../Fixtures/templates'); - $container->registerExtension(new TwigExtension()); - $this->loadFromFile($container, 'full', $format); - $this->loadFromFile($container, 'extra', $format); - $this->compileContainer($container); - - $def = $container->getDefinition('twig.loader.native_filesystem'); - $paths = []; - foreach ($def->getMethodCalls() as $call) { - if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) { - $paths[] = $call[1]; - } - } - - $this->assertEquals([ - ['path1'], - ['path2'], - ['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'], - [__DIR__.'/Fixtures/templates'], - ], $paths); - } - public function getFormats() { return [ diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/TwigBundle/views/layout.html.twig b/src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/TwigBundle/views/layout.html.twig deleted file mode 100644 index 1975b0e159..0000000000 --- a/src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/TwigBundle/views/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -{# Twig template #}