Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Zumba\GastonJS\Browser;
|
Chris@0
|
4
|
Chris@0
|
5
|
Chris@0
|
6 /**
|
Chris@0
|
7 * Trait BrowserConfigurationTrait
|
Chris@0
|
8 * @package Zumba\GastonJS\Browser
|
Chris@0
|
9 */
|
Chris@0
|
10 trait BrowserConfigurationTrait {
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Set whether to fail or not on javascript errors found on the page
|
Chris@0
|
13 * @param bool $enabled
|
Chris@0
|
14 * @return bool
|
Chris@0
|
15 */
|
Chris@0
|
16 public function jsErrors($enabled = true) {
|
Chris@0
|
17 return $this->command('set_js_errors', $enabled);
|
Chris@0
|
18 }
|
Chris@0
|
19
|
Chris@0
|
20 /**
|
Chris@0
|
21 * Set a blacklist of urls that we are not supposed to load
|
Chris@0
|
22 * @param array $blackList
|
Chris@0
|
23 * @return bool
|
Chris@0
|
24 */
|
Chris@0
|
25 public function urlBlacklist($blackList) {
|
Chris@0
|
26 return $this->command('set_url_blacklist', $blackList);
|
Chris@0
|
27 }
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * Set the debug mode on the browser
|
Chris@0
|
31 * @param bool $enable
|
Chris@0
|
32 * @return bool
|
Chris@0
|
33 */
|
Chris@0
|
34 public function debug($enable = false) {
|
Chris@0
|
35 $this->debug = $enable;
|
Chris@0
|
36 return $this->command('set_debug', $this->debug);
|
Chris@0
|
37 }
|
Chris@0
|
38
|
Chris@12
|
39 /**
|
Chris@12
|
40 * Set the timeout after which any resource requested will stop
|
Chris@12
|
41 * trying and proceed with other parts of the page
|
Chris@12
|
42 * @param int $resourceTimeout
|
Chris@12
|
43 * @return bool
|
Chris@12
|
44 */
|
Chris@12
|
45 public function resourceTimeout($resourceTimeout) {
|
Chris@12
|
46 return $this->command('set_resource_timeout', $resourceTimeout);
|
Chris@12
|
47 }
|
Chris@12
|
48
|
Chris@12
|
49 /**
|
Chris@12
|
50 * Sets or unsets web proxy.
|
Chris@12
|
51 *
|
Chris@12
|
52 * @param string|false $proxy proxy url formatted as '(http|socks5)://[username:password@]host:port', or false to unset
|
Chris@12
|
53 * @return bool
|
Chris@12
|
54 * @throws \UnexpectedValueException when the proxy url is invalid
|
Chris@12
|
55 */
|
Chris@12
|
56 public function setProxy($proxy)
|
Chris@12
|
57 {
|
Chris@12
|
58 $args = array('set_proxy');
|
Chris@12
|
59 if ($proxy !== false)
|
Chris@12
|
60 {
|
Chris@12
|
61 if (preg_match('~^(http|socks5)://(?:([^:@/]*?):([^:@/]*?)@)?([^:@/]+):(\d+)$~', $proxy, $components))
|
Chris@12
|
62 {
|
Chris@12
|
63 array_push($args, $components[4], intval($components[5], 10), $components[1]);
|
Chris@12
|
64 if (strlen($components[2]) || strlen($components[3]))
|
Chris@12
|
65 {
|
Chris@12
|
66 array_push($args, urldecode($components[2]), urldecode($components[3]));
|
Chris@12
|
67 }
|
Chris@12
|
68 }
|
Chris@12
|
69 else
|
Chris@12
|
70 {
|
Chris@12
|
71 throw new \UnexpectedValueException('Invalid proxy url ' . $proxy);
|
Chris@12
|
72 }
|
Chris@12
|
73 }
|
Chris@12
|
74 return call_user_func_array(array($this, 'command'), $args);
|
Chris@12
|
75 }
|
Chris@0
|
76 }
|