Skip to content

Commit

Permalink
Merge branch '3.4' into 4.3
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicolas-grekas committed Oct 2, 2019
2 parents 30b6f19 + 9f55b34 commit 499b3f3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions TwigEngine.php
Expand Up @@ -21,6 +21,7 @@
use Twig\Error\Error;
use Twig\Error\LoaderError;
use Twig\Loader\ExistsLoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\Template;

/**
Expand Down Expand Up @@ -78,19 +79,24 @@ public function exists($name)

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

if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
return $loader->exists((string) $name);
}
if (1 === Environment::MAJOR_VERSION && !$loader instanceof ExistsLoaderInterface) {
try {
// cast possible TemplateReferenceInterface to string because the
// EngineInterface supports them but LoaderInterface does not
if ($loader instanceof SourceContextLoaderInterface) {
$loader->getSourceContext((string) $name);
} else {
$loader->getSource((string) $name);
}

return true;
} catch (LoaderError $e) {
}

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

return true;
return $loader->exists((string) $name);
}

/**
Expand Down

0 comments on commit 499b3f3

Please sign in to comment.