Skip to content

Commit c9c3d66

Browse files
committed
bug #33273 Removed calls to Twig\Environment::loadTemplate() (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- Removed calls to Twig\Environment::loadTemplate() | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A This PR prepares #33039. Twig 3 does not have the `loadTemplate()` anymore, so this PR replaces calls to that method. Commits ------- ea9e375 Removed calls to Twig\Environment::loadTemplate().
2 parents 9475b2e + ea9e375 commit c9c3d66

File tree

6 files changed

+8
-10
lines changed

6 files changed

+8
-10
lines changed

src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function loadResourcesFromTheme($cacheKey, &$theme)
154154
{
155155
if (!$theme instanceof Template) {
156156
/* @var Template $theme */
157-
$theme = $this->environment->loadTemplate($theme);
157+
$theme = $this->environment->load($theme)->unwrap();
158158
}
159159

160160
if (null === $this->template) {

src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Symfony\Bridge\Twig\Extension\TranslationExtension;
1616
use Symfony\Component\Translation\Loader\ArrayLoader;
1717
use Symfony\Component\Translation\Translator;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1819
use Twig\Environment;
1920
use Twig\Loader\ArrayLoader as TwigArrayLoader;
21+
use Twig\TemplateWrapper;
2022

2123
class TranslationExtensionTest extends TestCase
2224
{
@@ -269,7 +271,7 @@ public function testDefaultTranslationDomainWithNamedArguments()
269271
$this->assertEquals('foo (custom)foo (foo)foo (custom)foo (custom)foo (fr)foo (custom)foo (fr)', trim($template->render([])));
270272
}
271273

272-
protected function getTemplate($template, $translator = null)
274+
private function getTemplate($template, TranslatorInterface $translator = null): TemplateWrapper
273275
{
274276
if (null === $translator) {
275277
$translator = new Translator('en');
@@ -283,6 +285,6 @@ protected function getTemplate($template, $translator = null)
283285
$twig = new Environment($loader, ['debug' => true, 'cache' => false]);
284286
$twig->addExtension(new TranslationExtension($translator));
285287

286-
return $twig->loadTemplate('index');
288+
return $twig->load('index');
287289
}
288290
}

src/Symfony/Bridge/Twig/TwigEngine.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function load($name)
126126
}
127127

128128
try {
129-
return $this->environment->loadTemplate((string) $name);
129+
return $this->environment->load((string) $name)->unwrap();
130130
} catch (LoaderError $e) {
131131
throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
132132
}

src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function warmUp($cacheDir)
7373

7474
foreach ($templates as $template) {
7575
try {
76-
$twig->loadTemplate($template);
76+
$twig->load($template);
7777
} catch (Error $e) {
7878
// problem during compilation, give up
7979
}

src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function warmUp($cacheDir)
4646

4747
foreach ($this->iterator as $template) {
4848
try {
49-
$this->twig->loadTemplate($template);
49+
$this->twig->load($template);
5050
} catch (Error $e) {
5151
// problem during compilation, give up
5252
// might be a syntax error or a non-Twig template

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

-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ protected function mockTwigEnvironment()
103103
{
104104
$this->twigEnvironment = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
105105

106-
$this->twigEnvironment->expects($this->any())
107-
->method('loadTemplate')
108-
->willReturn('loadedTemplate');
109-
110106
if (interface_exists('Twig\Loader\SourceContextLoaderInterface')) {
111107
$loader = $this->getMockBuilder('Twig\Loader\SourceContextLoaderInterface')->getMock();
112108
} else {

0 commit comments

Comments
 (0)