@@ -65,14 +65,12 @@ public function compile(JsPhpize $jsPhpize, $code, $fileName)
65
65
}
66
66
67
67
/**
68
- * @param CompilerInterface $compiler
69
- * @param string $output
68
+ * @param string $output
70
69
*
71
70
* @return string
72
71
*/
73
- protected function parseOutput ($ compiler , $ output )
72
+ protected function parseOutput ($ output )
74
73
{
75
- $ jsPhpize = $ this ->getJsPhpizeEngine ($ compiler );
76
74
$ output = preg_replace (
77
75
'/\{\s*\?><\?(?:php)?\s*\}/ ' ,
78
76
'{} ' ,
@@ -86,16 +84,6 @@ protected function parseOutput($compiler, $output)
86
84
$ output
87
85
);
88
86
89
- $ dependencies = $ jsPhpize ->compileDependencies ();
90
- if ($ dependencies !== '' ) {
91
- $ dependencies = $ compiler ->getFormatter ()->handleCode ($ dependencies );
92
- $ output = preg_match ('/^(<\?(?:php)?\s+namespace\s\S.*)(((?:;|\n|\?>)[\s\S]*)?)$/U ' , $ output , $ matches )
93
- ? $ matches [1 ] . $ dependencies . $ matches [2 ]
94
- : $ dependencies . $ output ;
95
- }
96
-
97
- $ jsPhpize ->flushDependencies ();
98
-
99
87
return $ output ;
100
88
}
101
89
@@ -104,8 +92,17 @@ public function handleOutputEvent(Compiler\Event\OutputEvent $event)
104
92
/** @var CompilerInterface $compiler */
105
93
$ compiler = $ event ->getTarget ();
106
94
107
- $ event ->setOutput ($ this ->parseOutput ($ compiler , $ event ->getOutput ()));
95
+ $ event ->setOutput ($ this ->parseOutput ($ event ->getOutput ()));
108
96
97
+ $ jsPhpize = $ this ->getJsPhpizeEngine ($ compiler );
98
+ $ dependencies = $ jsPhpize ->compileDependencies ();
99
+
100
+ if ($ dependencies !== '' ) {
101
+ $ dependencies = $ compiler ->getFormatter ()->handleCode ($ dependencies );
102
+ $ event ->prependOutput ($ dependencies );
103
+ }
104
+
105
+ $ jsPhpize ->flushDependencies ();
109
106
$ compiler ->unsetOption ('jsphpize_engine ' );
110
107
}
111
108
0 commit comments