/** * @small */ public function testRetrieval() { $http_proxy = new HttpProxy('http', 8080); $https_proxy = new HttpProxy('https', 8080); $ftp_proxy = new FtpProxy('ftp', 8080); $socks_proxy = new SocksProxy('socks', 8080); $collection = new NetworkProxyCollection(); $collection->setSocksProxy($socks_proxy); $this->assertTrue($collection->getProxy(ProxyScheme::FTP()) instanceof SocksProxy); $this->assertTrue($collection->getProxy(ProxyScheme::HTTP()) instanceof SocksProxy); $this->assertTrue($collection->getProxy(ProxyScheme::HTTPS()) instanceof SocksProxy); $collection->setFtpProxy($ftp_proxy); $this->assertTrue($collection->getProxy(ProxyScheme::FTP()) instanceof FtpProxy); $this->assertTrue($collection->getProxy(ProxyScheme::HTTP()) instanceof SocksProxy); $this->assertTrue($collection->getProxy(ProxyScheme::HTTPS()) instanceof SocksProxy); $collection->setHttpProxy($http_proxy); $this->assertTrue($collection->getProxy(ProxyScheme::FTP()) instanceof FtpProxy); $this->assertTrue($collection->getProxy(ProxyScheme::HTTP()) instanceof HttpProxy); $this->assertTrue($collection->getProxy(ProxyScheme::HTTPS()) instanceof SocksProxy); $collection->setHttpsProxy($https_proxy); $this->assertTrue($collection->getProxy(ProxyScheme::FTP()) instanceof FtpProxy); $this->assertTrue($collection->getProxy(ProxyScheme::HTTP()) instanceof HttpProxy); $this->assertTrue($collection->getProxy(ProxyScheme::HTTPS()) instanceof HttpProxy); $this->assertEquals('http', $collection->getProxy(ProxyScheme::HTTP())->getHostname()); $this->assertEquals('https', $collection->getProxy(ProxyScheme::HTTPS())->getHostname()); }
/** * Get the most appropriate proxy for the protocol * * @param ProxyScheme $protocol * @return NetworkProxyInterface|null */ public function getProxy(ProxyScheme $protocol) { $proxy = $this->socks_proxy; if ($protocol == ProxyScheme::HTTP() && $this->http_proxy) { $proxy = $this->http_proxy; } elseif ($protocol == ProxyScheme::HTTPS() && $this->https_proxy) { $proxy = $this->https_proxy; } elseif ($protocol == ProxyScheme::FTP() && $this->ftp_proxy) { $proxy = $this->ftp_proxy; } return $proxy; }