8000 [FrameworkBundle] Deprecate absolute template paths · symfony/symfony@274cd46 · GitHub
[go: up one dir, main page]

Skip to content

Commit 274cd46

Browse files
committed
[FrameworkBundle] Deprecate absolute template paths
1 parent b868feb commit 274cd46

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

UPGRADE-3.1.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ Form
1919
in `ResizeFormListener::preSubmit` method has been deprecated and will be
2020
removed in Symfony 4.0.
2121

22+
FrameworkBundle
23+
---------------
24+
25+
* As it was never an officially supported feature,
26+
the support for absolute template paths has been deprecated
27+
and will be removed in Symfony 4.0.
28+
2229
HttpKernel
2330
----------
2431

UPGRADE-4.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Form
1616
* Support for data objects that implements both `Traversable` and
1717
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed
1818

19+
FrameworkBundle
20+
---------------
21+
22+
* Support for absolute template paths has been removed from the template name parser.
23+
1924
HttpKernel
2025
----------
2126

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

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

77
* Added `Controller::json` to simplify creating JSON responses when using the Serializer component
8+
* Deprecated absolute template paths support in the template name parser
89

910
3.0.0
1011
-----

src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function parse($name)
5555
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
5656
}
5757

58-
if (!preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || $this->isAbsolutePath($name) || 0 === strpos($name, '@')) {
58+
if ($this->isAbsolutePath($name) || !preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || 0 === strpos($name, '@')) {
5959
return parent::parse($name);
6060
}
6161

@@ -74,6 +74,12 @@ public function parse($name)
7474

7575
private function isAbsolutePath($file)
7676
{
77-
return (bool) preg_match('#^(?:/|[a-zA-Z]:)#', $file);
77+
$isAbsolute = (bool) preg_match('#^(?:/|[a-zA-Z]:)#', $file);
78+
79+
if ($isAbsolute) {
80+
@trigger_error('Absolute template path support is deprecated since Symfony 3.1 and will throw an exception in 4.0.', E_USER_DEPRECATED);
81+
}
82+
83+
return $isAbsolute;
7884
}
7985
}

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ public function parseProvider()
6868
array('FooBundle:Post:foo.bar.index.html.php', 'FooBundle:Post:foo.bar.index.html.php', '@FooBundle/Resources/views/Post/foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
6969
array('@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', new BaseTemplateReference('@FooBundle/Resources/views/layout.html.twig', 'twig')),
7070
array('@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', new BaseTemplateReference('@FooBundle/Foo/layout.html.twig', 'twig')),
71-
array('/path/to/section/index.html.php', '/path/to/section/index.html.php', '/path/to/section/index.html.php', new BaseTemplateReference('/path/to/section/index.html.php', 'php')),
72-
array('C:\\path\\to\\section\\name.html.php', 'C:path/to/section/name.html.php', 'C:path/to/section/name.html.php', new BaseTemplateReference('C:path/to/section/name.html.php', 'php')),
73-
array('C:\\path\\to\\section\\name:foo.html.php', 'C:path/to/section/name:foo.html.php', 'C:path/to/section/name:foo.html.php', new BaseTemplateReference('C:path/to/section/name:foo.html.php', 'php')),
74-
array('\\path\\to\\section\\name.html.php', '/path/to/section/name.html.php', '/path/to/section/name.html.php', new BaseTemplateReference('/path/to/section/name.html.php', 'php')),
75-
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
7671
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
7772
array('name', 'name', 'name', new BaseTemplateReference('name')),
7873
array('default/index.html.php', '::default/index.html.php', 'views/default/index.html.php', new TemplateReference(null, null, 'default/index', 'html', 'php')),
@@ -86,4 +81,39 @@ public function testParseValidNameWithNotFoundBundle()
8681
{
8782
$this->parser->parse('BarBundle:Post:index.html.php');
8883
}
84+
85+
/**
86+
* @group legacy
87+
* @dataProvider provideAbsolutePaths
88+
*/
89+
public function testAbsolutePathsAreDeprecated($name, $logicalName, $path, $ref)
90+
{
91+
$deprecations = array();
92+
set_error_handler(function ($type, $msg) use (&$deprecations) {
93+
if (E_USER_DEPRECATED === $type) {
94+
$deprecations[] = $msg;
95+
}
96+
});
97+
98+
$template = $this->parser->parse($name);
99+
100+
restore_error_handler();
101+
102+
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
103+
$this->assertSame($logicalName, $template->getLogicalName());
104+
$this->assertSame($path, $template->getPath());
105+
$this->assertCount(1, $deprecations);
106+
$this->assertContains('Absolute template path support is deprecated since Symfony 3.1 and will throw an exception in 4.0.', $deprecations[0]);
107+
}
108+
109+
public function provideAbsolutePaths()
110+
{
111+
return array(
112+
array('/path/to/section/index.html.php', '/path/to/section/index.html.php', '/path/to/section/index.html.php', new BaseTemplateReference('/path/to/section/index.html.php', 'php')),
113+
array('C:\\path\\to\\section\\name.html.php', 'C:path/to/section/name.html.php', 'C:path/to/section/name.html.php', new BaseTemplateReference('C:path/to/section/name.html.php', 'php')),
114+
array('C:\\path\\to\\section\\name:foo.html.php', 'C:path/to/section/name:foo.html.php', 'C:path/to/section/name:foo.html.php', new BaseTemplateReference('C:path/to/section/name:foo.html.php', 'php')),
115+
array('\\path\\to\\section\\name.html.php', '/path/to/section/name.html.php', '/path/to/section/name.html.php', new BaseTemplateReference('/path/to/section/name.html.php', 'php')),
116+
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
117+
);
118+
}
89119
}

0 commit comments

Comments
 (0)
0