8000 Removed templateExists method everywhere · symfony/symfony@61b2d96 · GitHub
[go: up one dir, main page]

Skip to content

Commit 61b2d96

Browse files
committed
Removed templateExists method everywhere
1 parent 8172d0f commit 61b2d96

File tree

4 files changed

+16
-62
lines changed

4 files changed

+16
-62
lines changed

src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
5.0.0
5+
-----
6+
7+
* removed the `ExceptionController::templateExists()` method
8+
* removed the `TemplateManager::templateExists()` method
9+
410
4.3.0
511
-----
612

src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1818
use Symfony\Component\HttpKernel\Profiler\Profiler;
1919
use Twig\Environment;
20-
use Twig\Error\LoaderError;
21-
use Twig\Loader\ExistsLoaderInterface;
2220

2321
/**
2422
* ExceptionController.
@@ -97,7 +95,7 @@ public function cssAction(string $token)
9795

9896
$template = $this->getTemplate();
9997

100-
if (!$this->templateExists($template)) {
98+
if (!$this->twig->getLoader()->exists($template)) {
10199
return new Response($this->errorRenderer->getStylesheet(), 200, ['Content-Type' => 'text/css']);
102100
}
103101

@@ -108,22 +106,4 @@ protected function getTemplate()
108106
{
109107
return '@Twig/Exception/'.($this->debug ? 'exception' : 'error').'.html.twig';
110108
}
111-
112-
// to be removed when the minimum required version of Twig is >= 2.0
113-
protected function templateExists(string $template)
114-
{
115-
$loader = $this->twig->getLoader();
116-
if ($loader instanceof ExistsLoaderInterface) {
117-
return $loader->exists($template);
118-
}
119-
120-
try {
121-
$loader->getSource($template);
122-
123-
return true;
124-
} catch (LoaderError $e) {
125-
}
126-
127-
return false;
128-
}
129109
}

src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
use Symfony\Component\HttpKernel\Profiler\Profile;
1616
use Symfony\Component\HttpKernel\Profiler\Profiler;
1717
use Twig\Environment;
18-
use Twig\Error\LoaderError;
19-
use Twig\Loader\ExistsLoaderInterface;
20-
use Twig\Loader\SourceContextLoaderInterface;
21-
use Twig\Template;
2218

2319
/**
2420
* Profiler Templates Manager.
@@ -66,6 +62,7 @@ public function getName(Profile $profile, string $panel)
6662
*/
6763
public function getNames(Profile $profile)
6864
{
65+
$loader = $this->twig->getLoader();
6966
$templates = [];
7067

7168
foreach ($this->templates as $arguments) {
@@ -83,7 +80,7 @@ public function getNames(Profile $profile)
8380
$template = substr($template, 0, -10);
8481
}
8582

86-
if (!$this->templateExists($template.'.html.twig')) {
83+
if (!$loader->exists($template.'.html.twig')) {
8784
throw new \UnexpectedValueException(sprintf('The profiler template "%s.html.twig" for data collector "%s" does not exist.', $template, $name));
8885
}
8986

@@ -92,26 +89,4 @@ public function getNames(Profile $profile)
9289

9390
return $templates;
9491
}
95-
96-
// to be removed when the minimum required version of Twig is >= 2.0
97-
protected function templateExists(string $template)
98-
{
99-
$loader = $this->twig->getLoader();
100-
if ($loader instanceof ExistsLoaderInterface) {
101-
return $loader->exists($template);
102-
}
103-
104-
try {
105-
if ($loader instanceof SourceContextLoaderInterface || method_exists($loader, 'getSourceContext')) {
106-
$loader->getSourceContext($template);
107-
} else {
108-
$loader->getSource($template);
109-
}
110-
111-
return true;
112-
} catch (LoaderError $e) {
113-
}
114-
115-
return false;
116-
}
11792
}

src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ protected function setUp()
4545
$profiler = $this->mockProfiler();
4646
$twigEnvironment = $this->mockTwigEnvironment();
4747
$templates = [
48-
'data_collector.foo' => ['foo', 'FooBundle:Collector:foo'],
49-
'data_collector.bar' => ['bar', 'FooBundle:Collector:bar'],
50-
'data_collector.baz' => ['baz', 'FooBundle:Collector:baz'],
48+
'data_collector.foo' => ['foo', '@Foo/Collector/foo.html.twig'],
49+
'data_collector.bar' => ['bar', '@Foo/Collector/bar.html.twig'],
50+
'data_collector.baz' => ['baz', '@Foo/Collector/baz.html.twig'],
5151
];
5252 F56D

5353
$this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates);
@@ -71,7 +71,7 @@ public function testGetNameValidTemplate()
7171
->withAnyParameters()
7272
->willReturnCallback([$this, 'profilerHasCallback']);
7373

74-
$this->assertEquals('FooBundle:Collector:foo.html.twig', $this->templateManager->getName(new ProfileDummy(), 'foo'));
74+
$this->assertEquals('@Foo/Collector/foo.html.twig', $this->templateManager->getName(new ProfileDummy(), 'foo'));
7575
}
7676

7777
public function profilerHasCallback($panel)
@@ -103,17 +103,10 @@ protected function mockProfile()
103103

104104
protected function mockTwigEnvironment()
105105
{
106-
$this->twigEnvironment = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
107-
108-
$this->twigEnvironment->expects($this->any())
109-
->method('loadTemplate')
110-
->willReturn('loadedTemplate');
106+
$loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock();
107+
$loader->method('exists')->willReturn(true);
111108

112-
if (interface_exists('Twig\Loader\SourceContextLoaderInterface')) {
113-
$loader = $this->getMockBuilder('Twig\Loader\SourceContextLoaderInterface')->getMock();
114-
} else {
115-
$loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock();
116-
}
109+
$this->twigEnvironment = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
117110
$this->twigEnvironment->expects($this->any())->method('getLoader')->willReturn($loader);
118111

119112
return $this->twigEnvironment;

0 commit comments

Comments
 (0)
0