1 | <?php |
||
30 | class BrowserMob extends Module |
||
31 | { |
||
32 | |||
33 | protected $config = ['host', 'port', 'autostart', 'blacklist', 'whitelist', 'limits', 'timeouts', 'dns', 'retry', 'basicAuth', 'littleproxy']; |
||
34 | |||
35 | protected $requiredFields = ['host']; |
||
36 | |||
37 | protected $response; |
||
38 | |||
39 | private $bmp; |
||
40 | |||
41 | /** |
||
42 | * @codeCoverageIgnore |
||
43 | * @ignore Codeception specific |
||
44 | */ |
||
45 | public function _initialize() |
||
66 | |||
67 | protected static function __pingProxy($url) |
||
77 | |||
78 | protected function __setProxyCapabilities($options) |
||
79 | { |
||
80 | foreach ($options as $config => $data) { |
||
81 | if (false === empty($data)) { |
||
82 | switch ((string) $config) { |
||
83 | case 'blacklist': |
||
84 | foreach ($data['patterns'] as $pattern) { |
||
85 | $this->_blacklist($pattern, $data['code']); |
||
86 | if (false === $this->response->success) { |
||
87 | break; |
||
88 | } |
||
89 | } |
||
90 | break; |
||
91 | case 'whitelist': |
||
92 | $patterns = implode(',', $data['patterns']); |
||
93 | $this->_whitelist($patterns, $data['code']); |
||
94 | break; |
||
95 | case 'limits': |
||
96 | $this->_limits($data); |
||
97 | break; |
||
98 | case 'timeouts': |
||
99 | $this->_timeouts($data); |
||
100 | break; |
||
101 | case 'redirect': |
||
102 | foreach ($data as $entry) { |
||
103 | $this->_remapHosts($entry['domain'], $entry['ip']); |
||
104 | if (false === $this->response->success) { |
||
105 | break; |
||
106 | } |
||
107 | } |
||
108 | break; |
||
109 | case 'retry': |
||
110 | $this->_retry($data); |
||
111 | break; |
||
112 | case 'basicAuth': |
||
113 | foreach ($data as $entry) { |
||
114 | $this->_basicAuth($entry['domain'], $entry['options']); |
||
115 | if (false === $this->response->success) { |
||
116 | break; |
||
117 | } |
||
118 | } |
||
119 | break; |
||
120 | default: |
||
121 | // do nothing |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | |||
127 | public function getProxyPort() |
||
131 | |||
132 | public function openProxy($capabilities = null) |
||
133 | { |
||
134 | $this->_open(); |
||
135 | if (empty($capabilities)) { |
||
136 | $capabilities = $this->config; |
||
1 ignored issue
–
show
|
|||
137 | } |
||
138 | $this->__setProxyCapabilities($capabilities); |
||
139 | return $this->getProxyPort(); |
||
140 | } |
||
141 | |||
142 | public function closeProxy() |
||
143 | { |
||
144 | $this->_close(); |
||
145 | } |
||
146 | |||
147 | public function startHar() |
||
148 | { |
||
149 | $this->_newHar(); |
||
150 | return $this->response->success; |
||
151 | } |
||
152 | |||
153 | public function startPage() |
||
158 | |||
159 | public function getHar() |
||
160 | { |
||
161 | return $this->bmp->har; |
||
162 | } |
||
163 | |||
164 | public function setHeaders($headers) |
||
169 | |||
170 | public function redirectUrl($match, $replace) |
||
175 | |||
176 | // magic function that exposes BrowserMobProxy API pulic methods |
||
177 | public function __call($name, $args) |
||
203 | |||
204 | } |
||
205 |