File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212 */
1313class Twig extends Extractor implements ExtractorInterface
1414{
15- /**
16- * Twig instance.
17- *
18- * @var Twig_Environment
19- */
20- private static $ twig ;
15+ public static $ options = [
16+ 'twig ' => null
17+ ];
2118
2219 /**
2320 * {@inheritdoc}
2421 */
2522 public static function fromString ($ string , Translations $ translations , array $ options = [])
2623 {
27- $ string = self ::getTwig ()->compileSource ($ string );
24+ $ options += static ::$ options ;
25+
26+ $ twig = $ options ['twig ' ] ?: self ::createTwig ();
2827
29- PhpCode::fromString ($ string , $ translations , $ options );
28+ PhpCode::fromString ($ twig -> compileSource ( $ string) , $ translations , $ options );
3029 }
3130
3231 /**
3332 * Returns a Twig instance.
3433 *
3534 * @return Twig_Environment
3635 */
37- private static function getTwig ()
36+ private static function createTwig ()
3837 {
39- //Initialise twig
40- if (self ::$ twig === null ) {
41- self ::$ twig = new Twig_Environment (new Twig_Loader_String ());
42- self ::$ twig ->addExtension (new Twig_Extensions_Extension_I18n ());
43- }
38+ $ twig = new Twig_Environment (new Twig_Loader_String ());
39+ $ twig ->addExtension (new Twig_Extensions_Extension_I18n ());
4440
45- return self :: $ twig ;
41+ return static :: $ options [ ' twig ' ] = $ twig ;
4642 }
4743}
You can’t perform that action at this time.
0 commit comments