1 | <?php |
||
14 | class Driver_Phantomjs_Connection { |
||
15 | |||
16 | /** |
||
17 | * The file storing the pid of the current phantomjs server process |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $_pid_file; |
||
21 | |||
22 | /** |
||
23 | * The pid of the current phantomjs server process |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $_pid; |
||
27 | |||
28 | /** |
||
29 | * Ulr of the phantomjs server |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $_server = 'http://localhost'; |
||
33 | |||
34 | /** |
||
35 | * Port of the phantomjs server |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $_port; |
||
39 | |||
40 | /** |
||
41 | * Getter / Setter of the phantomjs server port. |
||
42 | * If none is set it tries to fine an unused port between 4445 and 5000 |
||
43 | * @param string $port |
||
44 | * @return string|Driver_Phantomjs_Connection |
||
45 | */ |
||
46 | 15 | public function port($port = NULL) |
|
61 | |||
62 | /** |
||
63 | * Getter / Setter of the current phantomjs server url |
||
64 | * @param string $server |
||
65 | * @return string|Driver_Phantomjs_Connection |
||
66 | */ |
||
67 | 15 | public function server($server = NULL) |
|
76 | |||
77 | /** |
||
78 | * Get the host of the current phantomjs server (without the protocol part) |
||
79 | * @return string |
||
80 | */ |
||
81 | 2 | public function host() |
|
85 | |||
86 | /** |
||
87 | * Getter, get the current phantomjs server process pid |
||
88 | * @return string |
||
89 | */ |
||
90 | 1 | public function pid() |
|
94 | |||
95 | 3 | public function __construct($server = NULL) |
|
102 | |||
103 | /** |
||
104 | * Start a new phantomjs server, optionally provide pid_file and log file. |
||
105 | * If you provide a pid_file, it will kill the process currently running on that pid, before starting the new one |
||
106 | * If the start is unsuccessfull it will return FALSE |
||
107 | * @param string $pid_file |
||
108 | * @param string $log_file |
||
109 | * @return boolean |
||
110 | */ |
||
111 | 2 | public function start($pid_file = NULL, $log_file = '/dev/null') |
|
136 | |||
137 | /** |
||
138 | * Check if the phantomjs server has been started |
||
139 | * @return boolean |
||
140 | */ |
||
141 | 2 | public function is_started() |
|
145 | |||
146 | /** |
||
147 | * Check if the phantomjs server is actually running (the port is taken) |
||
148 | * @return boolean |
||
149 | */ |
||
150 | 2 | public function is_running() |
|
154 | |||
155 | /** |
||
156 | * Gracefully stop the phantomjs server. Return FALSE on failure. Clear the pid_file if set |
||
157 | * @return boolean |
||
158 | */ |
||
159 | 2 | public function stop() |
|
177 | |||
178 | /** |
||
179 | * Getter - get the current pid_file |
||
180 | * @return string |
||
181 | */ |
||
182 | 1 | public function pid_file() |
|
186 | |||
187 | /** |
||
188 | * Perform a get request on the phantomjs server |
||
189 | * @param string $command |
||
190 | * @return mixed |
||
191 | */ |
||
192 | 10 | public function get($command) |
|
196 | |||
197 | /** |
||
198 | * Perform a post request on the phantomjs server |
||
199 | * @param string $command |
||
200 | * @param array $params |
||
201 | * @return mixed |
||
202 | */ |
||
203 | 10 | public function post($command, array $params) |
|
211 | |||
212 | /** |
||
213 | * Perform a delete request on the phantomjs server |
||
214 | * @param string $command |
||
215 | * @return mixed |
||
216 | */ |
||
217 | 3 | public function delete($command) |
|
224 | |||
225 | /** |
||
226 | * Get the full url of a command (including server and port) |
||
227 | * @param string $command |
||
228 | * @return string |
||
229 | */ |
||
230 | 15 | public function command_url($command) |
|
234 | |||
235 | /** |
||
236 | * Perform a custom request on the phantomjs server, using curl |
||
237 | * @param string $command |
||
238 | * @param array $options |
||
239 | * @return mixed |
||
240 | */ |
||
241 | 14 | protected function call($command, array $options = array()) |
|
272 | } |
||
273 |