@@ -118,9 +118,15 @@ public function send(RequestInterface $request, ResponseInterface $response, $fi
118
118
* @param ResponseInterface $response
119
119
* @return ResponseInterface
120
120
*/
121
- public function open (RequestInterface $ request , ResponseInterface $ response )
121
+ public function open (RequestInterface $ request , ResponseInterface $ response, $ delay = 0 )
122
122
{
123
- return $ this ->request ($ request , $ response , $ this ->openCmd );
123
+ if ($ delay ) {
124
+ $ cmd = sprintf ($ this ->openCmdWithDelay , $ delay );
125
+ } else {
126
+ $ cmd = $ this ->openCmd ;
127
+ }
128
+
129
+ return $ this ->request ($ request , $ response , $ cmd );
124
130
}
125
131
126
132
/**
@@ -182,6 +188,7 @@ public function setTimeout($period)
182
188
*/
183
189
protected function request (RequestInterface $ request , ResponseInterface $ response , $ cmd )
184
190
{
191
+
185
192
// Validate PhantomJS executable
186
193
if (!file_exists ($ this ->phantomJS ) || !is_executable ($ this ->phantomJS )) {
187
194
throw new NoPhantomJsException (sprintf ('PhantomJs file does not exist or is not executable: %s ' , $ this ->phantomJS ));
@@ -200,6 +207,8 @@ protected function request(RequestInterface $request, ResponseInterface $respons
200
207
$ request ->getBody (),
201
208
$ cmd
202
209
);
210
+
211
+
203
212
204
213
$ script = $ this ->writeScript ($ data );
205
214
$ cmd = escapeshellcmd (sprintf ("%s %s " , $ this ->phantomJS , $ script ));
@@ -314,10 +323,10 @@ protected function parse($data)
314
323
315
324
if (status === 'success') {
316
325
%6 \$s
317
- }
318
-
319
- console.log(JSON.stringify(response, undefined, 4) );
320
- phantom.exit();
326
+ } else {
327
+ console.log(JSON.stringify(response, undefined, 4));
328
+ phantom.exit( );
329
+ }
321
330
});
322
331
EOF ;
323
332
@@ -334,6 +343,9 @@ protected function parse($data)
334
343
response.content = page.evaluate(function () {
335
344
return document.getElementsByTagName('html')[0].innerHTML
336
345
});
346
+
347
+ console.log(JSON.stringify(response, undefined, 4));
348
+ phantom.exit();
337
349
EOF ;
338
350
339
351
/**
@@ -347,5 +359,31 @@ protected function parse($data)
347
359
response.content = page.evaluate(function () {
348
360
return document.getElementsByTagName('html')[0].innerHTML
349
361
});
362
+
363
+ console.log(JSON.stringify(response, undefined, 4));
364
+ phantom.exit();
365
+ EOF ;
366
+
367
+ /**
368
+ * PhantomJs page open
369
+ * command template
370
+ *
371
+ * @var string
372
+ */
373
+ protected $ openCmdWithDelay = <<<EOF
374
+
375
+ window.setTimeout(function(){
376
+
377
+
378
+ response.content = page.evaluate(function () {
379
+ return document.getElementsByTagName('html')[0].innerHTML
380
+ });
381
+
382
+
383
+ console.log(JSON.stringify(response, undefined, 4));
384
+ phantom.exit();
385
+
386
+ }, %s);
387
+
350
388
EOF ;
351
389
}
0 commit comments