Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 059113e

Browse filesBrowse files
committed
Removed templateExists method
1 parent 8172d0f commit 059113e
Copy full SHA for 059113e

File tree

4 files changed

+16
-62
lines changed
Filter options

4 files changed

+16
-62
lines changed

‎src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md
+6Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php
+1-21Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php
+2-27Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php
+7-14Lines 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

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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.