Skip to content

Commit 499b3f3

Browse files
Merge branch '3.4' into 4.3
* 3.4: Sync Twig templateExists behaviors Fix the :only-of-type pseudo class selector [Serializer] Add CsvEncoder tests for PHP 7.4 Copy phpunit.xsd to a predictable path [Security/Http] fix parsing X509 emailAddress [Serializer] fix denormalization of string-arrays with only one element #33731 [Cache] fix known tag versions ttl check
2 parents 30b6f19 + 9f55b34 commit 499b3f3

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

TwigEngine.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Twig\Error\Error;
2222
use Twig\Error\LoaderError;
2323
use Twig\Loader\ExistsLoaderInterface;
24+
use Twig\Loader\SourceContextLoaderInterface;
2425
use Twig\Template;
2526

2627
/**
@@ -78,19 +79,24 @@ public function exists($name)
7879

7980
$loader = $this->environment->getLoader();
8081

81-
if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
82-
return $loader->exists((string) $name);
83-
}
82+
if (1 === Environment::MAJOR_VERSION && !$loader instanceof ExistsLoaderInterface) {
83+
try {
84+
// cast possible TemplateReferenceInterface to string because the
85+
// EngineInterface supports them but LoaderInterface does not
86+
if ($loader instanceof SourceContextLoaderInterface) {
87+
$loader->getSourceContext((string) $name);
88+
} else {
89+
$loader->getSource((string) $name);
90+
}
91+
92+
return true;
93+
} catch (LoaderError $e) {
94+
}
8495

85-
try {
86-
// cast possible TemplateReferenceInterface to string because the
87-
// EngineInterface supports them but LoaderInterface does not
88-
$loader->getSourceContext((string) $name)->getCode();
89-
} catch (LoaderError $e) {
9096
return false;
9197
}
9298

93-
return true;
99+
return $loader->exists((string) $name);
94100
}
95101

96102
/**

0 commit comments

Comments
 (0)