9
9
use Phug \AbstractCompilerModule ;
10
10
use Phug \Compiler ;
11
11
use Phug \CompilerEvent ;
12
+ use Phug \CompilerInterface ;
12
13
use Phug \Renderer ;
13
14
use Phug \Util \ModuleContainerInterface ;
14
15
@@ -49,8 +50,7 @@ public function __construct(ModuleContainerInterface $container)
49
50
'patterns ' => [
50
51
'transform_expression ' => function ($ jsCode ) use ($ compiler ) {
51
52
52
- /** @var JsPhpize $jsPhpize */
53
- $ jsPhpize = $ compiler ->getOption ('jsphpize_engine ' );
53
+ $ jsPhpize = $ this ->getJsPhpizeEngine ($ compiler );
54
54
55
55
$ compilation = $ this ->compile ($ jsPhpize , $ jsCode , $ compiler ->getPath ());
56
56
@@ -64,6 +64,18 @@ public function __construct(ModuleContainerInterface $container)
64
64
]);
65
65
}
66
66
67
+ /**
68
+ * @return JsPhpize
69
+ */
70
+ public function getJsPhpizeEngine (CompilerInterface $ compiler )
71
+ {
72
+ if (!$ compiler ->hasOption ('jsphpize_engine ' )) {
73
+ $ compiler ->setOption ('jsphpize_engine ' , new JsPhpize ($ this ->getOptions ()));
74
+ }
75
+
76
+ return $ compiler ->getOption ('jsphpize_engine ' );
77
+ }
78
+
67
79
public function compile (JsPhpize $ jsPhpize , $ code , $ fileName )
68
80
{
69
81
try {
@@ -92,10 +104,6 @@ public function compile(JsPhpize $jsPhpize, $code, $fileName)
92
104
public function getEventListeners ()
93
105
{
94
106
return [
95
- CompilerEvent::COMPILE => function (Compiler \Event \CompileEvent $ event ) {
96
- $ event ->getTarget ()->setOption ('jsphpize_engine ' , new JsPhpize ($ this ->getOptions ()));
97
- },
98
-
99
107
CompilerEvent::OUTPUT => function (Compiler \Event \OutputEvent $ event ) {
100
108
$ compiler = $ event ->getTarget ();
101
109
0 commit comments