| 1 | <?php |
||
| 16 | class AspectProxy implements SplObserver |
||
| 17 | { |
||
| 18 | 5 | public function update(SplSubject $ev) |
|
| 19 | { |
||
| 20 | 5 | switch ((string)$ev) { |
|
| 21 | 5 | case 'pre-download': |
|
| 22 | 5 | $this->before($ev->refRequest()); |
|
| 23 | 5 | return; |
|
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | 5 | public static function before(HttpGetRequest $req) |
|
| 28 | { |
||
| 29 | // no_proxy skip |
||
| 30 | 5 | if (isset($_SERVER['no_proxy'])) { |
|
| 31 | $pattern = new NoProxyPattern($_SERVER['no_proxy']); |
||
| 32 | if ($pattern->test($req->getURL())) { |
||
| 33 | $req->curlOpts[CURLOPT_PROXY] = null; |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | 5 | $httpProxy = self::issetOr($_SERVER, 'http_proxy', 'HTTP_PROXY'); |
|
| 39 | 5 | if ($httpProxy && $req->scheme === 'http') { |
|
| 40 | $req->curlOpts[CURLOPT_PROXY] = $httpProxy; |
||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | 5 | $httpsProxy = self::issetOr($_SERVER, 'https_proxy', 'HTTPS_PROXY'); |
|
| 45 | 5 | if ($httpsProxy && $req->scheme === 'https') { |
|
| 46 | $req->curlOpts[CURLOPT_PROXY] = $httpsProxy; |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | 5 | $req->curlOpts[CURLOPT_PROXY] = null; |
|
| 51 | 5 | $req->curlOpts[CURLOPT_PROXYUSERPWD] = null; |
|
| 52 | 5 | } |
|
| 53 | |||
| 54 | 5 | private static function issetOr(array $arr, $key1, $key2) |
|
| 64 | } |
||
| 65 |