@@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
99
99
$ template .= fread (STDIN , 1024 );
100
100
}
101
101
102
- return $ this ->display ($ input , $ output , array ($ this ->validate ($ twig , $ template )));
102
+ return $ this ->display ($ input , $ output , array ($ this ->validate ($ twig , $ template, uniqid ( ' sf_ ' ) )));
103
103
}
104
104
105
105
$ filesInfo = array ();
@@ -121,11 +121,17 @@ protected function findFiles($filename)
121
121
throw new \RuntimeException (sprintf ('File or directory "%s" is not readable ' , $ filename ));
122
122
}
123
123
124
- private function validate (\Twig_Environment $ twig , $ template , $ file = null )
124
+ private function validate (\Twig_Environment $ twig , $ template , $ file )
125
125
{
126
+ $ realLoader = $ twig ->getLoader ();
126
127
try {
127
- $ twig ->parse ($ twig ->tokenize ($ template , $ file ? (string ) $ file : null ));
128
+ $ temporaryLoader = new \Twig_Loader_Array (array ((string ) $ file => $ template ));
129
+ $ twig ->setLoader ($ temporaryLoader );
130
+ $ nodeTree = $ twig ->parse ($ twig ->tokenize ($ template , (string ) $ file ));
131
+ $ twig ->compile ($ nodeTree );
132
+ $ twig ->setLoader ($ realLoader );
128
133
} catch (\Twig_Error $ e ) {
134
+ $ twig ->setLoader ($ realLoader );
129
135
return array ('template ' => $ template , 'file ' => $ file , 'valid ' => false , 'exception ' => $ e );
130
136
}
131
137
0 commit comments