*/ class ProxyManager { /** @var ?string */ private $error = null; /** @var ?ProxyItem */ private $httpProxy = null; /** @var ?ProxyItem */ private $httpsProxy = null; /** @var ?NoProxyPattern */ private $noProxyHandler = null; /** @var ?self */ private static $instance = null; private function __construct() { try { $this->getProxyData(); } catch (\RuntimeException $e) { $this->error = $e->getMessage(); } } public static function getInstance(): ProxyManager { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } /** * Clears the persistent instance */ public static function reset(): void { self::$instance = null; } public function hasProxy(): bool { return $this->httpProxy !== null || $this->httpsProxy !== null; } /** * Returns a RequestProxy instance for the request url * * @param non-empty-string $requestUrl */ public function getProxyForRequest(string $requestUrl): RequestProxy { if ($this->error !== null) { throw new TransportException('Unable to use a proxy: '.$this->error); } $scheme = (string) parse_url($requestUrl, PHP_URL_SCHEME); $proxy = $this->getProxyForScheme($scheme); if ($proxy === null) { return RequestProxy::none(); } if ($this->noProxy($requestUrl)) { return RequestProxy::noProxy(); } return $proxy->toRequestProxy($scheme); } /** * Returns a ProxyItem if one is set for the scheme, otherwise null */ private function getProxyForScheme(string $scheme): ?ProxyItem { if ($scheme === 'http') { return $this->httpProxy; } if ($scheme === 'https') { return $this->httpsProxy; } return null; } /** * Finds proxy values from the environment and sets class properties */ private function getProxyData(): void { // Handle http_proxy/HTTP_PROXY on CLI only for security reasons if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { [$env, $name] = $this->getProxyEnv('http_proxy'); if ($env !== null) { $this->httpProxy = new ProxyItem($env, $name); } } // Handle cgi_http_proxy/CGI_HTTP_PROXY if needed if ($this->httpProxy === null) { [$env, $name] = $this->getProxyEnv('cgi_http_proxy'); if ($env !== null) { $this->httpProxy = new ProxyItem($env, $name); } } // Handle https_proxy/HTTPS_PROXY [$env, $name] = $this->getProxyEnv('https_proxy'); if ($env !== null) { $this->httpsProxy = new ProxyItem($env, $name); } // Handle no_proxy/NO_PROXY [$env, $name] = $this->getProxyEnv('no_proxy'); if ($env !== null) { $this->noProxyHandler = new NoProxyPattern($env); } } /** * Searches $_SERVER for case-sensitive values * * @return array{0: string|null, 1: string} value, name */ private function getProxyEnv(string $envName): array { $names = [strtolower($envName), strtoupper($envName)]; foreach ($names as $name) { if (is_string($_SERVER[$name] ?? null)) { if ($_SERVER[$name] !== '') { return [$_SERVER[$name], $name]; } } } return [null, '']; } /** * Returns true if a url matches no_proxy value */ private function noProxy(string $requestUrl): bool { if ($this->noProxyHandler === null) { return false; } return $this->noProxyHandler->test($requestUrl); } }__halt_compiler();----SIGNATURE:----qK+FyoCoeS9Yf8tubuVRUfuq68/Eke2x8BkS0C7dAkYzk6UDPTVgJ7b5WLPTPFWPSGhLN672smMVXQZKhIXHQ4juYIjydcAWRS01xL4PQsMlhvYcx8ENzVU5ReJu/TDqnVSUGh+vIZz+9RR5TdkMUCE88xRK7FsZ634IBURCixZYIJjhcgr3We4jUf3w6T4niO+lMmuxmX5k5sO8ushlZ8aKMHWpzH8ZuLfNwQwSxnJAE2QYsMn0/rCeRhe47DHO0Fay3+SUTWx2oQEvgB+RECJIDM0dhcglYgDKMT6m5jqP0n1cI4A842ydcIoEkilXNa1HqYW9Ofv/wEM3buUWZ8BY94+QXNrtQLghkzgyH3jtH1jpDm3NZSZoC6hbUPv6N9PsQxfwmdjAbNPTJ3DPjfgOaP3wJSQbtu+ckW04jzfY6pFNRmNjA0BzV++B5WBc4ce9B1sowAaej9XDvGU4Mk1BQWFg5Zesm50kokawnW+6n+OZ7qSpsv0v9Hwd6hU3kXvlyTAgOu0sefjPXCt4kmYf2aole4thmEvJ3fja9pwOFnwZP8JRCesMfhplNSqVxeoca+X6qJEvxwpWvqSrykTVY2k2+XirnsGPB34uLxBGZCQPHyCSSgwzljyi7ZXpgoJBoraD6dj3XkEKlHV628ZLCeBoVCi8dFaBgxnKQ/o=----ATTACHMENT:----NjIyNjQwMDA5MzY5NjA2NiAzMzQ1ODM4MzE1MjI5ODE1IDE2NTc1Njc0Mzc0MDA5NDQ=