@@ -132,6 +132,13 @@ class Capture
132
132
*/
133
133
protected $ includedJsSnippets = array ();
134
134
135
+ /**
136
+ * List of options which will be passed to phantomjs
137
+ *
138
+ * @var array
139
+ */
140
+ protected $ options = array ();
141
+
135
142
/**
136
143
* Capture constructor.
137
144
*/
@@ -217,12 +224,19 @@ public function save($imageLocation, $deleteFileIfExists = true)
217
224
file_put_contents ($ jobPath , $ resultString );
218
225
}
219
226
220
- $ command = sprintf ("%sphantomjs %s " , $ this ->binPath , $ jobPath );
227
+ $ command = sprintf ("%sphantomjs %s %s " , $ this ->binPath , $ this -> getOptionsString () , $ jobPath );
221
228
$ result = exec (escapeshellcmd ($ command ));
222
229
223
230
return file_exists ($ this ->imageLocation );
224
231
}
225
232
233
+ /**
234
+ * @param string $templateName
235
+ * @param array $args
236
+ *
237
+ * @return string
238
+ * @throws TemplateNotFoundException
239
+ */
226
240
private function getTemplateResult ($ templateName , array $ args )
227
241
{
228
242
$ templatePath = $ this ->templatePath . DIRECTORY_SEPARATOR . $ templateName . '.php ' ;
@@ -236,6 +250,26 @@ private function getTemplateResult($templateName, array $args)
236
250
return ob_get_clean ();
237
251
}
238
252
253
+ /**
254
+ * @return string
255
+ */
256
+ private function getOptionsString ()
257
+ {
258
+ if (empty ($ this ->options )) {
259
+ return '' ;
260
+ }
261
+
262
+ $ mappedOptions = array_map (function ($ value , $ key ) {
263
+ if (substr ($ key , 0 , 2 ) === '-- ' ) {
264
+ $ key = substr ($ key , 2 );
265
+ }
266
+
267
+ return sprintf ("--%s=%s " , $ key , $ value );
268
+ }, $ this ->options , array_keys ($ this ->options ));
269
+
270
+ return implode (' ' , $ mappedOptions );
271
+ }
272
+
239
273
/**
240
274
* Sets the path to PhantomJS binary, example: "/usr/bin"
241
275
*
@@ -415,4 +449,18 @@ public function includeJs($script)
415
449
416
450
return $ this ;
417
451
}
452
+
453
+ /**
454
+ * Sets the options which will be passed to phantomjs
455
+ *
456
+ * @param array $options
457
+ *
458
+ * @return $this
459
+ */
460
+ public function setOptions ($ options )
461
+ {
462
+ $ this ->options = $ options ;
463
+
464
+ return $ this ;
465
+ }
418
466
}
0 commit comments