Removed templateExists method

This commit is contained in:
Yonel Ceruto 2019-07-09 11:32:42 -04:00
parent 8172d0ffbb
commit 059113e11f
4 changed files with 16 additions and 62 deletions

View File

@ -1,6 +1,12 @@
CHANGELOG
=========
5.0.0
-----
* removed the `ExceptionController::templateExists()` method
* removed the `TemplateManager::templateExists()` method
4.3.0
-----

View File

@ -17,8 +17,6 @@ use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Loader\ExistsLoaderInterface;
/**
* ExceptionController.
@ -97,7 +95,7 @@ class ExceptionController
$template = $this->getTemplate();
if (!$this->templateExists($template)) {
if (!$this->twig->getLoader()->exists($template)) {
return new Response($this->errorRenderer->getStylesheet(), 200, ['Content-Type' => 'text/css']);
}
@ -108,22 +106,4 @@ class ExceptionController
{
return '@Twig/Exception/'.($this->debug ? 'exception' : 'error').'.html.twig';
}
// to be removed when the minimum required version of Twig is >= 2.0
protected function templateExists(string $template)
{
$loader = $this->twig->getLoader();
if ($loader instanceof ExistsLoaderInterface) {
return $loader->exists($template);
}
try {
$loader->getSource($template);
return true;
} catch (LoaderError $e) {
}
return false;
}
}

View File

@ -15,10 +15,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Loader\ExistsLoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\Template;
/**
* Profiler Templates Manager.
@ -66,6 +62,7 @@ class TemplateManager
*/
public function getNames(Profile $profile)
{
$loader = $this->twig->getLoader();
$templates = [];
foreach ($this->templates as $arguments) {
@ -83,7 +80,7 @@ class TemplateManager
$template = substr($template, 0, -10);
}
if (!$this->templateExists($template.'.html.twig')) {
if (!$loader->exists($template.'.html.twig')) {
throw new \UnexpectedValueException(sprintf('The profiler template "%s.html.twig" for data collector "%s" does not exist.', $template, $name));
}
@ -92,26 +89,4 @@ class TemplateManager
return $templates;
}
// to be removed when the minimum required version of Twig is >= 2.0
protected function templateExists(string $template)
{
$loader = $this->twig->getLoader();
if ($loader instanceof ExistsLoaderInterface) {
return $loader->exists($template);
}
try {
if ($loader instanceof SourceContextLoaderInterface || method_exists($loader, 'getSourceContext')) {
$loader->getSourceContext($template);
} else {
$loader->getSource($template);
}
return true;
} catch (LoaderError $e) {
}
return false;
}
}

View File

@ -45,9 +45,9 @@ class TemplateManagerTest extends TestCase
$profiler = $this->mockProfiler();
$twigEnvironment = $this->mockTwigEnvironment();
$templates = [
'data_collector.foo' => ['foo', 'FooBundle:Collector:foo'],
'data_collector.bar' => ['bar', 'FooBundle:Collector:bar'],
'data_collector.baz' => ['baz', 'FooBundle:Collector:baz'],
'data_collector.foo' => ['foo', '@Foo/Collector/foo.html.twig'],
'data_collector.bar' => ['bar', '@Foo/Collector/bar.html.twig'],
'data_collector.baz' => ['baz', '@Foo/Collector/baz.html.twig'],
];
$this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates);
@ -71,7 +71,7 @@ class TemplateManagerTest extends TestCase
->withAnyParameters()
->willReturnCallback([$this, 'profilerHasCallback']);
$this->assertEquals('FooBundle:Collector:foo.html.twig', $this->templateManager->getName(new ProfileDummy(), 'foo'));
$this->assertEquals('@Foo/Collector/foo.html.twig', $this->templateManager->getName(new ProfileDummy(), 'foo'));
}
public function profilerHasCallback($panel)
@ -103,17 +103,10 @@ class TemplateManagerTest extends TestCase
protected function mockTwigEnvironment()
{
$loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock();
$loader->method('exists')->willReturn(true);
$this->twigEnvironment = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
$this->twigEnvironment->expects($this->any())
->method('loadTemplate')
->willReturn('loadedTemplate');
if (interface_exists('Twig\Loader\SourceContextLoaderInterface')) {
$loader = $this->getMockBuilder('Twig\Loader\SourceContextLoaderInterface')->getMock();
} else {
$loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock();
}
$this->twigEnvironment->expects($this->any())->method('getLoader')->willReturn($loader);
return $this->twigEnvironment;