File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed
Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change 1919use Twig \Error \Error ;
2020use Twig \Error \LoaderError ;
2121use Twig \Loader \ExistsLoaderInterface ;
22+ use Twig \Loader \SourceContextLoaderInterface ;
2223use Twig \Template ;
2324
2425/**
@@ -74,19 +75,24 @@ public function exists($name)
7475
7576 $ loader = $ this ->environment ->getLoader ();
7677
77- if ($ loader instanceof ExistsLoaderInterface || method_exists ($ loader , 'exists ' )) {
78- return $ loader ->exists ((string ) $ name );
79- }
78+ if (1 === Environment::MAJOR_VERSION && !$ loader instanceof ExistsLoaderInterface) {
79+ try {
80+ // cast possible TemplateReferenceInterface to string because the
81+ // EngineInterface supports them but LoaderInterface does not
82+ if ($ loader instanceof SourceContextLoaderInterface) {
83+ $ loader ->getSourceContext ((string ) $ name );
84+ } else {
85+ $ loader ->getSource ((string ) $ name );
86+ }
87+
88+ return true ;
89+ } catch (LoaderError $ e ) {
90+ }
8091
81- try {
82- // cast possible TemplateReferenceInterface to string because the
83- // EngineInterface supports them but LoaderInterface does not
84- $ loader ->getSourceContext ((string ) $ name )->getCode ();
85- } catch (LoaderError $ e ) {
8692 return false ;
8793 }
8894
89- return true ;
95+ return $ loader -> exists (( string ) $ name ) ;
9096 }
9197
9298 /**
You can’t perform that action at this time.
0 commit comments