@@ -41,8 +41,9 @@ public function getOption($key, $default = null)
41
41
/**
42
42
* Compile file or code (detect if $input is an exisisting file, else use it as content).
43
43
*
44
- * @param string $input file or content
45
- * @param string $filename if specified, input is used as content and filename as its name
44
+ * @param string $input file or content
45
+ * @param string $filename if specified, input is used as content and filename as its name
46
+ * @param bool $catchDependencies if true, dependencies are not compiled and can be grouped and get separatly
46
47
*
47
48
* @return string
48
49
*/
@@ -65,7 +66,8 @@ public function compile($input, $filename = null, $catchDependencies = false)
65
66
/**
66
67
* Compile a file.
67
68
*
68
- * @param string $file input file
69
+ * @param string $file input file
70
+ * @param bool $catchDependencies if true, dependencies are not compiled and can be grouped and get separatly
69
71
*
70
72
* @return string
71
73
*/
@@ -77,7 +79,8 @@ public function compileFile($file, $catchDependencies = false)
77
79
/**
78
80
* Compile raw code.
79
81
*
80
- * @param string $code input code
82
+ * @param string $code input code
83
+ * @param bool $catchDependencies if true, dependencies are not compiled and can be grouped and get separatly
81
84
*
82
85
* @return string
83
86
*/
@@ -87,7 +90,10 @@ public function compileCode($code, $catchDependencies = false)
87
90
}
88
91
89
92
/**
90
- * @param string $input file or content
93
+ * Compile without the dependencies.
94
+ *
95
+ * @param string $input file or content
96
+ * @param string $filename if specified, input is used as content and filename as its name
91
97
*
92
98
* @return string
93
99
*/
@@ -97,7 +103,9 @@ public function compileWithoutDependencies($input, $filename = null)
97
103
}
98
104
99
105
/**
100
- * @return mixed
106
+ * Return compiled dependencies caught during previous compilations.
107
+ *
108
+ * @return string
101
109
*/
102
110
public function compileDependencies ()
103
111
{
@@ -110,11 +118,14 @@ public function compileDependencies()
110
118
}
111
119
112
120
/**
113
- * @param string $input file or content
121
+ * Compile and return the code execution result.
122
+ *
123
+ * @param string $input file or content
124
+ * @param string $filename if specified, input is used as content and filename as its name
114
125
*
115
126
* @return mixed
116
127
*/
117
- public function render ($ input )
128
+ public function render ($ input, $ filename = null )
118
129
{
119
130
if (!in_array ($ this ->stream , $ this ->streamsRegistered )) {
120
131
$ this ->streamsRegistered [] = $ this ->stream ;
@@ -126,7 +137,7 @@ public function render($input)
126
137
}
127
138
128
139
try {
129
- return include $ this ->stream . '://data;<?php ' . $ this ->compile ($ input );
140
+ return include $ this ->stream . '://data;<?php ' . $ this ->compile ($ input, $ filename );
130
141
} catch (\JsPhpize \Compiler \Exception $ e ) {
131
142
throw $ e ;
132
143
} catch (\JsPhpize \Lexer \Exception $ e ) {
@@ -141,4 +152,28 @@ public function render($input)
141
152
throw new Exception ("An error occur in [ $ summary]: \n" . $ e ->getMessage (), 2 , E_ERROR , __FILE__ , __LINE__ , $ e );
142
153
}
143
154
}
155
+
156
+ /**
157
+ * Render a file.
158
+ *
159
+ * @param string $file input file
160
+ *
161
+ * @return string
162
+ */
163
+ public function renderFile ($ file )
164
+ {
165
+ return $ this ->render (file_get_contents ($ file ), $ file );
166
+ }
167
+
168
+ /**
169
+ * Render raw code.
170
+ *
171
+ * @param string $code input code
172
+ *
173
+ * @return string
174
+ */
175
+ public function renderCode ($ code )
176
+ {
177
+ return $ this ->compile ($ code , 'source.js ' );
178
+ }
144
179
}
0 commit comments