|
|
@@ -118,9 +118,15 @@ class Client implements ClientInterface
|
|
|
* @param ResponseInterface $response
|
|
|
* @return ResponseInterface
|
|
|
*/
|
|
|
- public function open(RequestInterface $request, ResponseInterface $response)
|
|
|
+ public function open(RequestInterface $request, ResponseInterface $response, $delay = 0)
|
|
|
{
|
|
|
- return $this->request($request, $response, $this->openCmd);
|
|
|
+ if ($delay) {
|
|
|
+ $cmd = sprintf($this->openCmdWithDelay, $delay);
|
|
|
+ } else {
|
|
|
+ $cmd = $this->openCmd;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->request($request, $response, $cmd);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -182,6 +188,7 @@ class Client implements ClientInterface
|
|
|
*/
|
|
|
protected function request(RequestInterface $request, ResponseInterface $response, $cmd)
|
|
|
{
|
|
|
+
|
|
|
// Validate PhantomJS executable
|
|
|
if (!file_exists($this->phantomJS) || !is_executable($this->phantomJS)) {
|
|
|
throw new NoPhantomJsException(sprintf('PhantomJs file does not exist or is not executable: %s', $this->phantomJS));
|
|
|
@@ -200,6 +207,8 @@ class Client implements ClientInterface
|
|
|
$request->getBody(),
|
|
|
$cmd
|
|
|
);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
$script = $this->writeScript($data);
|
|
|
$cmd = escapeshellcmd(sprintf("%s %s", $this->phantomJS, $script));
|
|
|
@@ -314,10 +323,10 @@ class Client implements ClientInterface
|
|
|
|
|
|
if (status === 'success') {
|
|
|
%6\$s
|
|
|
- }
|
|
|
-
|
|
|
- console.log(JSON.stringify(response, undefined, 4));
|
|
|
- phantom.exit();
|
|
|
+ } else {
|
|
|
+ console.log(JSON.stringify(response, undefined, 4));
|
|
|
+ phantom.exit();
|
|
|
+ }
|
|
|
});
|
|
|
EOF;
|
|
|
|
|
|
@@ -334,6 +343,9 @@ EOF;
|
|
|
response.content = page.evaluate(function () {
|
|
|
return document.getElementsByTagName('html')[0].innerHTML
|
|
|
});
|
|
|
+
|
|
|
+ console.log(JSON.stringify(response, undefined, 4));
|
|
|
+ phantom.exit();
|
|
|
EOF;
|
|
|
|
|
|
/**
|
|
|
@@ -347,5 +359,31 @@ EOF;
|
|
|
response.content = page.evaluate(function () {
|
|
|
return document.getElementsByTagName('html')[0].innerHTML
|
|
|
});
|
|
|
+
|
|
|
+ console.log(JSON.stringify(response, undefined, 4));
|
|
|
+ phantom.exit();
|
|
|
+EOF;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PhantomJs page open
|
|
|
+ * command template
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $openCmdWithDelay = <<<EOF
|
|
|
+
|
|
|
+ window.setTimeout(function(){
|
|
|
+
|
|
|
+
|
|
|
+ response.content = page.evaluate(function () {
|
|
|
+ return document.getElementsByTagName('html')[0].innerHTML
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ console.log(JSON.stringify(response, undefined, 4));
|
|
|
+ phantom.exit();
|
|
|
+
|
|
|
+ }, %s);
|
|
|
+
|
|
|
EOF;
|
|
|
}
|