Removed calls to Twig\Environment::loadTemplate().

This commit is contained in:
Alexander M. Turek 2019-08-21 11:17:06 +02:00
parent 451daa0b06
commit ea9e375b0b
6 changed files with 8 additions and 10 deletions

View File

@ -154,7 +154,7 @@ class TwigRendererEngine extends AbstractRendererEngine
{
if (!$theme instanceof Template) {
/* @var Template $theme */
$theme = $this->environment->loadTemplate($theme);
$theme = $this->environment->load($theme)->unwrap();
}
if (null === $this->template) {

View File

@ -15,8 +15,10 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Translator;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
use Twig\Loader\ArrayLoader as TwigArrayLoader;
use Twig\TemplateWrapper;
class TranslationExtensionTest extends TestCase
{
@ -269,7 +271,7 @@ class TranslationExtensionTest extends TestCase
$this->assertEquals('foo (custom)foo (foo)foo (custom)foo (custom)foo (fr)foo (custom)foo (fr)', trim($template->render([])));
}
protected function getTemplate($template, $translator = null)
private function getTemplate($template, TranslatorInterface $translator = null): TemplateWrapper
{
if (null === $translator) {
$translator = new Translator('en');
@ -283,6 +285,6 @@ class TranslationExtensionTest extends TestCase
$twig = new Environment($loader, ['debug' => true, 'cache' => false]);
$twig->addExtension(new TranslationExtension($translator));
return $twig->loadTemplate('index');
return $twig->load('index');
}
}

View File

@ -126,7 +126,7 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
}
try {
return $this->environment->loadTemplate((string) $name);
return $this->environment->load((string) $name)->unwrap();
} catch (LoaderError $e) {
throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}

View File

@ -73,7 +73,7 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface, ServiceSubscribe
foreach ($templates as $template) {
try {
$twig->loadTemplate($template);
$twig->load($template);
} catch (Error $e) {
// problem during compilation, give up
}

View File

@ -46,7 +46,7 @@ class TemplateCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInte
foreach ($this->iterator as $template) {
try {
$this->twig->loadTemplate($template);
$this->twig->load($template);
} catch (Error $e) {
// problem during compilation, give up
// might be a syntax error or a non-Twig template

View File

@ -103,10 +103,6 @@ class TemplateManagerTest extends TestCase
{
$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 {