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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Removed capability to load Twig template from legacy directories
  • Loading branch information
yceruto committed May 30, 2019
commit 4b6752bf3ec1e0df1c364030dd20c9853af0f5a8
34 changes: 2 additions & 32 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,18 @@ 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();

$this->twig = $twig;
$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()
Expand Down Expand Up @@ -397,22 +383,6 @@ private function findWrongBundleOverrides(): array
$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);
Expand Down
26 changes: 0 additions & 26 deletions src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,6 @@ public function testWarningsWrongBundleOverriding()
$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").
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/TwigBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<BundleName>/views/`

4.2.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,6 @@ public function load(array $configs, ContainerBuilder $container)
}
}

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]);
}
Expand Down Expand Up @@ -176,13 +167,6 @@ private function getBundleTemplatePaths(ContainerBuilder $container, array $conf
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,43 +197,6 @@ public function testTwigLoaderPaths($format)
], $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 [
Expand Down

This file was deleted.