Skip to content

Commit 85a9d67

Browse files
committed
[FrameworkBundle] Deprecate absolute template paths
1 parent 6fb9fee commit 85a9d67

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

UPGRADE-3.1.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ 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, the support for absolute
26+
template paths has been deprecated and will be removed in Symfony 4.0.
27+
2228
HttpKernel
2329
----------
2430

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 be removed in 4.0.', E_USER_DEPRECATED);
81+
}
82+
83+
return $isAbsolute;
7884
}
7985
}

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

Lines changed: 37 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,41 @@ 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+
throw new \LogicException(sprintf('Unexpected error: "%s".', $msg));
95+
}
96+
97+
$deprecations[] = $msg;
98+
});
99+
100+
$template = $this->parser->parse($name);
101+
102+
restore_error_handler();
103+
104+
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
105+
$this->assertSame($logicalName, $template->getLogicalName());
106+
$this->assertSame($path, $template->getPath());
107+
$this->assertCount(1, $deprecations);
108+
$this->assertContains('Absolute template path support is deprecated since Symfony 3.1 and will be removed in 4.0.', $deprecations[0]);
109+
}
110+
111+
public function provideAbsolutePaths()
112+
{
113+
return array(
114+
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')),
115+
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')),
116+
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')),
117+
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')),
118+
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
119+
);
120+
}
89121
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy