[FrameworkBundle] Deprecate absolute template paths
This commit is contained in:
parent
6fb9fee200
commit
85a9d67e93
@ -19,6 +19,12 @@ Form
|
|||||||
in `ResizeFormListener::preSubmit` method has been deprecated and will be
|
in `ResizeFormListener::preSubmit` method has been deprecated and will be
|
||||||
removed in Symfony 4.0.
|
removed in Symfony 4.0.
|
||||||
|
|
||||||
|
FrameworkBundle
|
||||||
|
---------------
|
||||||
|
|
||||||
|
* As it was never an officially supported feature, the support for absolute
|
||||||
|
template paths has been deprecated and will be removed in Symfony 4.0.
|
||||||
|
|
||||||
HttpKernel
|
HttpKernel
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
@ -16,6 +16,11 @@ Form
|
|||||||
* Support for data objects that implements both `Traversable` and
|
* Support for data objects that implements both `Traversable` and
|
||||||
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed
|
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed
|
||||||
|
|
||||||
|
FrameworkBundle
|
||||||
|
---------------
|
||||||
|
|
||||||
|
* Support for absolute template paths has been removed from the template name parser.
|
||||||
|
|
||||||
HttpKernel
|
HttpKernel
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ CHANGELOG
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
* Added `Controller::json` to simplify creating JSON responses when using the Serializer component
|
* Added `Controller::json` to simplify creating JSON responses when using the Serializer component
|
||||||
|
* Deprecated absolute template paths support in the template name parser
|
||||||
|
|
||||||
3.0.0
|
3.0.0
|
||||||
-----
|
-----
|
||||||
|
@ -55,7 +55,7 @@ class TemplateNameParser extends BaseTemplateNameParser
|
|||||||
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
|
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || $this->isAbsolutePath($name) || 0 === strpos($name, '@')) {
|
if ($this->isAbsolutePath($name) || !preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || 0 === strpos($name, '@')) {
|
||||||
return parent::parse($name);
|
return parent::parse($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +74,12 @@ class TemplateNameParser extends BaseTemplateNameParser
|
|||||||
|
|
||||||
private function isAbsolutePath($file)
|
private function isAbsolutePath($file)
|
||||||
{
|
{
|
||||||
return (bool) preg_match('#^(?:/|[a-zA-Z]:)#', $file);
|
$isAbsolute = (bool) preg_match('#^(?:/|[a-zA-Z]:)#', $file);
|
||||||
|
|
||||||
|
if ($isAbsolute) {
|
||||||
|
@trigger_error('Absolute template path support is deprecated since Symfony 3.1 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $isAbsolute;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,11 +68,6 @@ class TemplateNameParserTest extends TestCase
|
|||||||
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')),
|
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')),
|
||||||
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')),
|
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')),
|
||||||
array('@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', new BaseTemplateReference('@FooBundle/Foo/layout.html.twig', 'twig')),
|
array('@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', new BaseTemplateReference('@FooBundle/Foo/layout.html.twig', 'twig')),
|
||||||
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')),
|
|
||||||
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')),
|
|
||||||
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')),
|
|
||||||
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')),
|
|
||||||
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
|
|
||||||
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
|
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
|
||||||
array('name', 'name', 'name', new BaseTemplateReference('name')),
|
array('name', 'name', 'name', new BaseTemplateReference('name')),
|
||||||
array('default/index.html.php', '::default/index.html.php', 'views/default/index.html.php', new TemplateReference(null, null, 'default/index', 'html', 'php')),
|
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 @@ class TemplateNameParserTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->parser->parse('BarBundle:Post:index.html.php');
|
$this->parser->parse('BarBundle:Post:index.html.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
* @dataProvider provideAbsolutePaths
|
||||||
|
*/
|
||||||
|
public function testAbsolutePathsAreDeprecated($name, $logicalName, $path, $ref)
|
||||||
|
{
|
||||||
|
$deprecations = array();
|
||||||
|
set_error_handler(function ($type, $msg) use (&$deprecations) {
|
||||||
|
if (E_USER_DEPRECATED !== $type) {
|
||||||
|
throw new \LogicException(sprintf('Unexpected error: "%s".', $msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
$deprecations[] = $msg;
|
||||||
|
});
|
||||||
|
|
||||||
|
$template = $this->parser->parse($name);
|
||||||
|
|
||||||
|
restore_error_handler();
|
||||||
|
|
||||||
|
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
|
||||||
|
$this->assertSame($logicalName, $template->getLogicalName());
|
||||||
|
$this->assertSame($path, $template->getPath());
|
||||||
|
$this->assertCount(1, $deprecations);
|
||||||
|
$this->assertContains('Absolute template path support is deprecated since Symfony 3.1 and will be removed in 4.0.', $deprecations[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideAbsolutePaths()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
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')),
|
||||||
|
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')),
|
||||||
|
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')),
|
||||||
|
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')),
|
||||||
|
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user