8
8
*/
9
9
namespace JonnyW \PhantomJs ;
10
10
11
- use JonnyW \PhantomJs \ClientInterface ;
12
11
use JonnyW \PhantomJs \Exception \NoPhantomJsException ;
13
12
use JonnyW \PhantomJs \Exception \CommandFailedException ;
14
13
use JonnyW \PhantomJs \Exception \NotWriteableException ;
@@ -27,14 +26,14 @@ class Client implements ClientInterface
27
26
/**
28
27
* Client instance
29
28
*
30
- * @var JonnyW\PhantomJs\ClientInterface
29
+ * @var \ JonnyW\PhantomJs\ClientInterface
31
30
*/
32
31
private static $ instance ;
33
32
34
33
/**
35
34
* Message factory instance
36
35
*
37
- * @var JonnyW\PhantomJs\Message\FactoryInterface
36
+ * @var \ JonnyW\PhantomJs\Message\FactoryInterface
38
37
*/
39
38
protected $ factory ;
40
39
@@ -55,7 +54,7 @@ class Client implements ClientInterface
55
54
/**
56
55
* Internal constructor
57
56
*
58
- * @param FactoryInterface $factory
57
+ * @param \JonnyW\PhantomJs\Message\ FactoryInterface $factory
59
58
* @return void
60
59
*/
61
60
public function __construct (FactoryInterface $ factory = null )
@@ -64,16 +63,16 @@ public function __construct(FactoryInterface $factory = null)
64
63
$ factory = Factory::getInstance ();
65
64
}
66
65
67
- $ this ->factory = $ factory ;
68
- $ this ->phantomJS = 'bin/phantomjs ' ;
66
+ $ this ->factory = $ factory ;
67
+ $ this ->phantomJS = 'bin/phantomjs ' ;
69
68
$ this ->timeout = 5000 ;
70
69
}
71
70
72
71
/**
73
72
* Get singleton instance
74
73
*
75
- * @param FactoryInterface $factory
76
- * @return Client
74
+ * @param \JonnyW\PhantomJs\Message\ FactoryInterface $factory
75
+ * @return \JonnyW\PhantomJs\ Client
77
76
*/
78
77
public static function getInstance (FactoryInterface $ factory = null )
79
78
{
@@ -87,7 +86,7 @@ public static function getInstance(FactoryInterface $factory = null)
87
86
/**
88
87
* Get message factory instance
89
88
*
90
- * @return JonnyW\PhantomJs\Message\FactoryInterface
89
+ * @return \ JonnyW\PhantomJs\Message\FactoryInterface
91
90
*/
92
91
public function getMessageFactory ()
93
92
{
@@ -97,10 +96,10 @@ public function getMessageFactory()
97
96
/**
98
97
* Send request
99
98
*
100
- * @param RequestInterface $request
101
- * @param ResponseInterface $response
102
- * @param string $file
103
- * @return ResponseInterface
99
+ * @param \JonnyW\PhantomJs\Message\ RequestInterface $request
100
+ * @param \JonnyW\PhantomJs\Message\ ResponseInterface $response
101
+ * @param string $file
102
+ * @return \JonnyW\PhantomJs\Message\ ResponseInterface
104
103
*/
105
104
public function send (RequestInterface $ request , ResponseInterface $ response , $ file = null )
106
105
{
@@ -114,14 +113,14 @@ public function send(RequestInterface $request, ResponseInterface $response, $fi
114
113
/**
115
114
* Open page
116
115
*
117
- * @param RequestInterface $request
118
- * @param ResponseInterface $response
119
- * @return ResponseInterface
116
+ * @param \JonnyW\PhantomJs\Message\ RequestInterface $request
117
+ * @param \JonnyW\PhantomJs\Message\ ResponseInterface $response
118
+ * @return \JonnyW\PhantomJs\Message\ ResponseInterface
120
119
*/
121
120
public function open (RequestInterface $ request , ResponseInterface $ response , $ delay = 0 )
122
121
{
123
122
if ($ delay ) {
124
- $ cmd = sprintf ($ this ->openCmdWithDelay , $ delay );
123
+ $ cmd = sprintf ($ this ->openCmdWithDelay , $ delay );
125
124
} else {
126
125
$ cmd = $ this ->openCmd ;
127
126
}
@@ -132,10 +131,10 @@ public function open(RequestInterface $request, ResponseInterface $response, $de
132
131
/**
133
132
* Screen capture
134
133
*
135
- * @param RequestInterface $request
136
- * @param ResponseInterface $response
137
- * @param string $file
138
- * @return ResponseInterface
134
+ * @param \JonnyW\PhantomJs\Message\ RequestInterface $request
135
+ * @param \JonnyW\PhantomJs\Message\ ResponseInterface $response
136
+ * @param string $file
137
+ * @return \JonnyW\PhantomJs\Message\ ResponseInterface
139
138
*/
140
139
public function capture (RequestInterface $ request , ResponseInterface $ response , $ file )
141
140
{
@@ -151,8 +150,8 @@ public function capture(RequestInterface $request, ResponseInterface $response,
151
150
/**
152
151
* Set new PhantomJs path
153
152
*
154
- * @param string $path
155
- * @return Client
153
+ * @param string $path
154
+ * @return \JonnyW\PhantomJs\ Client
156
155
*/
157
156
public function setPhantomJs ($ path )
158
157
{
@@ -168,8 +167,8 @@ public function setPhantomJs($path)
168
167
/**
169
168
* Set timeout period (in milliseconds)
170
169
*
171
- * @param int $period
172
- * @return Client
170
+ * @param int $period
171
+ * @return \JonnyW\PhantomJs\ Client
173
172
*/
174
173
public function setTimeout ($ period )
175
174
{
@@ -181,10 +180,10 @@ public function setTimeout($period)
181
180
/**
182
181
* Make PhantomJS request
183
182
*
184
- * @param RequestInterface $request
185
- * @param ResponseInterface $response
186
- * @param string $cmd
187
- * @return ResponseInterface
183
+ * @param \JonnyW\PhantomJs\Message\ RequestInterface $request
184
+ * @param \JonnyW\PhantomJs\Message\ ResponseInterface $response
185
+ * @param string $cmd
186
+ * @return \JonnyW\PhantomJs\Message\ ResponseInterface
188
187
*/
189
188
protected function request (RequestInterface $ request , ResponseInterface $ response , $ cmd )
190
189
{
@@ -207,8 +206,6 @@ protected function request(RequestInterface $request, ResponseInterface $respons
207
206
$ request ->getBody (),
208
207
$ cmd
209
208
);
210
-
211
-
212
209
213
210
$ script = $ this ->writeScript ($ data );
214
211
$ cmd = escapeshellcmd (sprintf ("%s %s " , $ this ->phantomJS , $ script ));
@@ -261,8 +258,8 @@ protected function writeScript($data)
261
258
/**
262
259
* Remove temporary script file
263
260
*
264
- * @param string|boolean $file
265
- * @return Client
261
+ * @param string|boolean $file
262
+ * @return \JonnyW\PhantomJs\ Client
266
263
*/
267
264
protected function removeScript ($ file )
268
265
{
@@ -326,7 +323,7 @@ protected function parse($data)
326
323
} else {
327
324
console.log(JSON.stringify(response, undefined, 4));
328
325
phantom.exit();
329
- }
326
+ }
330
327
});
331
328
EOF ;
332
329
@@ -364,26 +361,24 @@ protected function parse($data)
364
361
phantom.exit();
365
362
EOF ;
366
363
367
- /**
364
+ /**
368
365
* PhantomJs page open
369
- * command template
366
+ * command template with
367
+ * delay
370
368
*
371
369
* @var string
372
370
*/
373
371
protected $ openCmdWithDelay = <<<EOF
374
372
375
- window.setTimeout(function(){
376
-
373
+ window.setTimeout(function () {
377
374
378
375
response.content = page.evaluate(function () {
379
376
return document.getElementsByTagName('html')[0].innerHTML
380
377
});
381
378
382
-
383
379
console.log(JSON.stringify(response, undefined, 4));
384
- phantom.exit();
380
+ phantom.exit();
385
381
386
382
}, %s);
387
-
388
383
EOF ;
389
384
}
0 commit comments