Commit f8a74187ab70f82ae4cd1a28e6b6479ab89542d3

Authored by Elena.Budnik
1 parent 55da2eac

case when PROXY_HOST is undefined

Showing 1 changed file with 33 additions and 31 deletions   Show diff stats
php/classes/ProxyUtils.php
1 1 <?php
2 2  
3 3 class ProxyUtils {
4   - static function addProxyForCurl(&$ch) {
5   - $proxy_host = PROXY_HOST;
6   - if (!empty($proxy_host)) {
7   - curl_setopt($ch, CURLOPT_PROXY, "http://".$proxy_host);
8   - $proxy_userpwd = PROXY_USERPWD;
9   - if (!empty($proxy_userpwd)) {
10   - curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_userpwd);
11   - }
12   - }
13   - }
  4 + static function addProxyForCurl(&$ch) {
  5 + if ( defined(PROXY_HOST) ) {
  6 + $proxy_host = PROXY_HOST;
  7 + if (!empty($proxy_host)) {
  8 + curl_setopt($ch, CURLOPT_PROXY, "http://".$proxy_host);
  9 + $proxy_userpwd = PROXY_USERPWD;
  10 + if (!empty($proxy_userpwd)) {
  11 + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_userpwd);
  12 + }
  13 + }
  14 + }
  15 + }
14 16  
15   - static function getStreamContextWithProxy() {
16   - $proxy_host = PROXY_HOST;
17   - if (empty($proxy_host))
18   - return;
19   - $options = array(
20   - 'http' => array(
21   - 'method' => 'GET',
22   - 'timeout' => '5',
23   - 'user_agent' => 'PHP libxml agent',
24   - 'ignore_errors' => true,
25   - )
26   - );
27   - $options['http']['proxy'] = 'tcp://'.$proxy_host;
28   - $options['http']['request_fulluri'] = TRUE;
29   - $proxy_userpwd = PROXY_USERPWD;
30   - if (!empty($proxy_userpwd)) {
31   - $options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode($proxy_userpwd);
32   - }
33   - return stream_context_create($options);
34   - }
  17 + static function getStreamContextWithProxy() {
  18 + $proxy_host = PROXY_HOST;
  19 + if (!defined(PROXY_HOST) || empty($proxy_host))
  20 + return;
  21 + $options = array(
  22 + 'http' => array(
  23 + 'method' => 'GET',
  24 + 'timeout' => '5',
  25 + 'user_agent' => 'PHP libxml agent',
  26 + 'ignore_errors' => true,
  27 + )
  28 + );
  29 +
  30 + $options['http']['proxy'] = 'tcp://'.$proxy_host;
  31 + $options['http']['request_fulluri'] = TRUE;
  32 + $proxy_userpwd = PROXY_USERPWD;
  33 + if (!empty($proxy_userpwd)) {
  34 + $options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode($proxy_userpwd);
  35 + }
  36 + return stream_context_create($options);
  37 + }
35 38 }
36   -
37 39 ?>
... ...