Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 904ff1c

Browse files
committed
Removed capability to load Twig template from legacy directories
1 parent 3fec468 commit 904ff1c

File tree

7 files changed

+2
-100
lines changed

7 files changed

+2
-100
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,17 @@ class DebugCommand extends Command
3838
private $projectDir;
3939
private $bundlesMetadata;
4040
private $twigDefaultPath;
41-
private $rootDir;
4241
private $filesystemLoaders;
4342
private $fileLinkFormatter;
4443

45-
public function __construct(Environment $twig, string $projectDir = null, array $bundlesMetadata = [], string $twigDefaultPath = null, string $rootDir = null, FileLinkFormatter $fileLinkFormatter = null)
44+
public function __construct(Environment $twig, string $projectDir = null, array $bundlesMetadata = [], string $twigDefaultPath = null, FileLinkFormatter $fileLinkFormatter = null)
4645
{
4746
parent::__construct();
4847

4948
$this->twig = $twig;
5049
$this->projectDir = $projectDir;
5150
$this->bundlesMetadata = $bundlesMetadata;
5251
$this->twigDefaultPath = $twigDefaultPath;
53-
$this->rootDir = $rootDir;
5452
$this->fileLinkFormatter = $fileLinkFormatter;
5553
}
5654

@@ -385,22 +383,6 @@ private function findWrongBundleOverrides(): array
385383
$alternatives = [];
386384
$bundleNames = [];
387385

388-
if ($this->rootDir && $this->projectDir) {
389-
$folders = glob($this->rootDir.'/Resources/*/views', GLOB_ONLYDIR);
390-
$relativePath = ltrim(substr($this->rootDir.\DIRECTORY_SEPARATOR.'Resources/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
391-
$bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) {
392-
if (0 === strpos($absolutePath, $this->projectDir)) {
393-
$name = basename(\dirname($absolutePath));
394-
$path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR);
395-
$carry[$name] = $path;
396-
397-
@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);
398-
}
399-
400-
return $carry;
401-
}, $bundleNames);
402-
}
403-
404386
if ($this->twigDefaultPath && $this->projectDir) {
405387
$folders = glob($this->twigDefaultPath.'/bundles/*', GLOB_ONLYDIR);
406388
$relativePath = ltrim(substr($this->twigDefaultPath.'/bundles/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);

src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,6 @@ public function testWarningsWrongBundleOverriding()
6363
$this->assertEquals($expected, json_decode($tester->getDisplay(true), true));
6464
}
6565

66-
/**
67-
* @group legacy
68-
* @expectedDeprecation Loading Twig templates from the "%sResources/BarBundle/views" directory is deprecated since Symfony 4.2, use "%stemplates/bundles/BarBundle" instead.
69-
*/
70-
public function testDeprecationForWrongBundleOverridingInLegacyPath()
71-
{
72-
$bundleMetadata = [
73-
'TwigBundle' => 'vendor/twig-bundle/',
74-
'WebProfilerBundle' => 'vendor/web-profiler-bundle/',
75-
];
76-
$defaultPath = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'templates';
77-
$rootDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
78-
79-
$tester = $this->createCommandTester([], $bundleMetadata, $defaultPath, $rootDir);
80-
$ret = $tester->execute(['--filter' => 'unknown', '--format' => 'json'], ['decorated' => false]);
81-
82-
$expected = ['warnings' => [
83-
'Path "Resources/BarBundle" not matching any bundle found',
84-
'Path "templates/bundles/UnknownBundle" not matching any bundle found',
85-
'Path "templates/bundles/WebProfileBundle" not matching any bundle found, did you mean "WebProfilerBundle"?',
86-
]];
87-
88-
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
89-
$this->assertEquals($expected, json_decode($tester->getDisplay(true), true));
90-
}
91-
9266
/**
9367
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
9468
* @expectedExceptionMessage Malformed namespaced template name "@foo" (expecting "@namespace/template_name").

src/Symfony/Bundle/TwigBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* updated default value for the `strict_variables` option to `%kernel.debug%` parameter
8+
* removed support to load templates from the legacy directories `src/Resources/views/` and `src/Resources/<BundleName>/views/`
89

910
4.2.0
1011
-----

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,6 @@ public function load(array $configs, ContainerBuilder $container)
120120
}
121121
}
122122

123-
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) {
124-
if ($dir !== $defaultTwigPath) {
125-
@trigger_error(sprintf('Loading Twig templates from the "%s" directory is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultTwigPath), E_USER_DEPRECATED);
126-
}
127-
128-
$twigFilesystemLoaderDefinition->addMethodCall('addPath', [$dir]);
129-
}
130-
$container->addResource(new FileExistenceResource($dir));
131-
132123
if (file_exists($defaultTwigPath)) {
133124
$twigFilesystemLoaderDefinition->addMethodCall('addPath', [$defaultTwigPath]);
134125
}
@@ -176,13 +167,6 @@ private function getBundleTemplatePaths(ContainerBuilder $container, array $conf
176167
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
177168
$defaultOverrideBundlePath = $container->getParameterBag()->resolveValue($config['default_path']).'/bundles/'.$name;
178169

179-
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views')) {
180-
@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);
181-
182-
$bundleHierarchy[$name][] = $dir;
183-
}
184-
$container->addResource(new FileExistenceResource($dir));
185-
186170
if (file_exists($defaultOverrideBundlePath)) {
187171
$bundleHierarchy[$name][] = $defaultOverrideBundlePath;
188172
}

src/Symfony/Bundle/TwigBundle/Resources/config/console.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<argument>%kernel.project_dir%</argument>
1313
<argument>%kernel.bundles_metadata%</argument>
1414
<argument>%twig.default_path%</argument>
15-
<argument>%kernel.root_dir%</argument>
1615
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
1716
<tag name="console.command" command="debug:twig" />
1817
</service>

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -197,43 +197,6 @@ public function testTwigLoaderPaths($format)
197197
], $paths);
198198
}
199199

200-
/**
201-
* @group legacy
202-
* @dataProvider getFormats
203-
* @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.
204-
* @expectedDeprecation Loading Twig templates from the "%s/Resources/views" directory is deprecated since Symfony 4.2, use "%s/templates" instead.
205-
*/
206-
public function testLegacyTwigLoaderPaths($format)
207-
{
208-
$container = $this->createContainer(__DIR__.'/../Fixtures/templates');
209-
$container->registerExtension(new TwigExtension());
210-
$this->loadFromFile($container, 'full', $format);
211-
$this->loadFromFile($container, 'extra', $format);
212-
$this->compileContainer($container);
213-
214-
$def = $container->getDefinition('twig.loader.native_filesystem');
215-
$paths = [];
216-
foreach ($def->getMethodCalls() as $call) {
217-
if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) {
218-
$paths[] = $call[1];
219-
}
220-
}
221-
222-
$this->assertEquals([
223-
['path1'],
224-
['path2'],
225-
['namespaced_path1', 'namespace1'],
226-
['namespaced_path2', 'namespace2'],
227-
['namespaced_path3', 'namespace3'],
228-
[__DIR__.'/../Fixtures/templates/Resources/TwigBundle/views', 'Twig'],
229-
[__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'],
230-
[realpath(__DIR__.'/../..').'/Resources/views', 'Twig'],
231-
[realpath(__DIR__.'/../..').'/Resources/views', '!Twig'],
232-
[__DIR__.'/../Fixtures/templates/Resources/views'],
233-
[__DIR__.'/Fixtures/templates'],
234-
], $paths);
235-
}
236-
237200
public function getFormats()
238201
{
239202
return [

src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/TwigBundle/views/layout.html.twig

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)