Skip to content

Commit 378429c

Browse files
committed
Merge pull request #1 from Aerowalk/master
Added viewportSize and replaced bin file with linux version
2 parents 6c92d35 + 68adf58 commit 378429c

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

Diff for: bin/phantomjs

27.4 MB
Binary file not shown.

Diff for: src/JonnyW/PhantomJs/Client.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ protected function request(RequestInterface $request, ResponseInterface $respons
204204
$request->getUrl(),
205205
$request->getMethod(),
206206
$request->getBody(),
207-
$cmd
207+
$cmd,
208+
$request->getViewportWidth(),
209+
$request->getViewportHeight()
208210
);
209211

210212
$script = $this->writeScript($data);
@@ -306,7 +308,7 @@ protected function parse($data)
306308
307309
page.settings.resourceTimeout = %2\$s;
308310
page.onResourceTimeout = function (e) {
309-
response = e;
311+
response = e;
310312
response.status = e.errorCode;
311313
};
312314
@@ -315,6 +317,11 @@ protected function parse($data)
315317
};
316318
317319
page.customHeaders = headers ? headers : {};
320+
321+
page.viewportSize = {
322+
width: %7\$s,
323+
height: %8\$s
324+
};
318325
319326
page.open('%3\$s', '%4\$s', '%5\$s', function (status) {
320327

Diff for: src/JonnyW/PhantomJs/Message/Request.php

+70
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ class Request implements RequestInterface
4646
* @var string
4747
*/
4848
protected $url;
49+
50+
/**
51+
* Viewport width
52+
*
53+
* @var int
54+
*/
55+
protected $viewportWidth;
56+
57+
/**
58+
* Viewport height
59+
*
60+
* @var int
61+
*/
62+
protected $viewportHeight;
4963

5064
/**
5165
* Internal constructor
@@ -139,6 +153,62 @@ public function getUrl()
139153

140154
return $url;
141155
}
156+
157+
/**
158+
* Set viewport width
159+
*
160+
* @param string $viewport_width
161+
* @return \JonnyW\PhantomJs\Message\Request
162+
*/
163+
public function setViewportWidth($viewport_width)
164+
{
165+
// Validate width
166+
if (!is_numeric($viewport_width)) {
167+
throw new Exception('Invalid viewport width provided');
168+
}
169+
170+
$this->viewportWidth = $viewport_width;
171+
172+
return $this;
173+
}
174+
175+
/**
176+
* Get viewport width
177+
*
178+
* @return int
179+
*/
180+
public function getViewportWidth()
181+
{
182+
return $this->viewportWidth ? $this->viewportWidth : 1024;
183+
}
184+
185+
/**
186+
* Set viewport height
187+
*
188+
* @param string $viewport_height
189+
* @return \JonnyW\PhantomJs\Message\Request
190+
*/
191+
public function setViewportHeight($viewport_height)
192+
{
193+
// Validate height
194+
if (!is_numeric($viewport_height)) {
195+
throw new Exception('Invalid viewport height provided');
196+
}
197+
198+
$this->viewportHeight = $viewport_height;
199+
200+
return $this;
201+
}
202+
203+
/**
204+
* Get viewport height
205+
*
206+
* @return int
207+
*/
208+
public function getViewportHeight()
209+
{
210+
return $this->viewportHeight ? $this->viewportHeight : 768;
211+
}
142212

143213
/**
144214
* Get content body

Diff for: src/JonnyW/PhantomJs/Message/RequestInterface.php

+30
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@ public function setUrl($url);
5555
* @return string
5656
*/
5757
public function getUrl();
58+
59+
/**
60+
* Set viewport width
61+
*
62+
* @param int $viewport_width
63+
* @return \JonnyW\PhantomJs\Message\RequestInterface
64+
*/
65+
public function setViewportWidth($viewport_width);
66+
67+
/**
68+
* Get viewport width
69+
*
70+
* @return int
71+
*/
72+
public function getViewportWidth();
73+
74+
/**
75+
* Set viewport height
76+
*
77+
* @param int $viewport_height
78+
* @return \JonnyW\PhantomJs\Message\RequestInterface
79+
*/
80+
public function setViewportHeight($viewport_height);
81+
82+
/**
83+
* Get viewport height
84+
*
85+
* @return int
86+
*/
87+
public function getViewportHeight();
5888

5989
/**
6090
* Get content body

0 commit comments

Comments
 (0)