public function proxify(\Zend\Http\Client $client, array $options = [])
    {
        if ($this->proxyConfig) {
            $host = $client->getUri()->getHost();
            if (!$this->isLocal($host)) {
                $proxyType =  $this->proxyConfig['proxy_type'] ?? 'default';

                if ($proxyType == 'socks5') {
                    $adapter = new \Zend\Http\Client\Adapter\Curl();
                    // Apply standard proxy options for Curl adapter:
                    $this->setCurlProxyOptions($adapter);
                    // Add SOCKS5 settings:
                    $adapter->setCurlOption(CURLOPT_FOLLOWLOCATION, true);
                    $adapter->setCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
                    $client->setAdapter($adapter);
                } elseif ($proxyType == 'default') {
                    // If the user has manually configured a Curl adapter,
                    // configure it for proxy compatibility; otherwise, create
                    // a fresh Proxy adapter.
                    if ($this->hasCurlAdapterAsDefault()) {
                        $adapter = new \Zend\Http\Client\Adapter\Curl();
                        $this->setCurlProxyOptions($adapter);
                    } else {
                        $adapter = new \Zend\Http\Client\Adapter\Proxy();
                        $options = array_replace($this->proxyConfig, $options);
                        $adapter->setOptions($options);
                    }
                    $client->setAdapter($adapter);
                }
            }
        }
        return $client;
    }
public function proxify(\Zend\Http\Client $client, array $options = [])
    {
        if ($this->proxyConfig) {
            $host = $client->getUri()->getHost();
            if (!$this->isLocal($host)) {
                $proxyType =  $this->proxyConfig['proxy_type'] ?? 'default';

                if ($proxyType == 'socks5') {
                    $adapter = new \Zend\Http\Client\Adapter\Curl();
                    // Apply standard proxy options for Curl adapter:
                    $this->setCurlProxyOptions($adapter);
                    // Add SOCKS5 settings:
                    $adapter->setCurlOption(CURLOPT_FOLLOWLOCATION, true);
                    $adapter->setCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
                    $client->setAdapter($adapter);
                } elseif ($proxyType == 'default') {
                    // If the user has manually configured a Curl adapter,
                    // configure it for proxy compatibility; otherwise, create
                    // a fresh Proxy adapter.
                    if ($this->hasCurlAdapterAsDefault()) {
                        $adapter = new \Zend\Http\Client\Adapter\Curl();
                        $this->setCurlProxyOptions($adapter);
                    } else {
                        $adapter = new \Zend\Http\Client\Adapter\Proxy();
                        $options = array_replace($this->proxyConfig, $options);
                        $adapter->setOptions($options);
                    }
                    $client->setAdapter($adapter);
                }
            }
        }
        return $client;
    }
public function proxify ( \ Zend \ Http \ Client $ client , array $ options = [ ] ) { if ( $ this -> proxyConfig ) { $ host = $ client -> getUri ( ) -> getHost ( ) ; if ( ! $ this -> isLocal ( $ host ) ) { $ proxyType = $ this -> proxyConfig [ 'proxy_type' ] ?? 'default' ; if ( $ proxyType == 'socks5' ) { $ adapter = new \ Zend \ Http \ Client \ Adapter \ Curl ( ) ; // Apply standard proxy options for Curl adapter: $ this -> setCurlProxyOptions ( $ adapter ) ; // Add SOCKS5 settings: $ adapter -> setCurlOption ( CURLOPT_FOLLOWLOCATION , true ) ; $ adapter -> setCurlOption ( CURLOPT_PROXYTYPE , CURLPROXY_SOCKS5 ) ; $ client -> setAdapter ( $ adapter ) ; } elseif ( $ proxyType == 'default' ) { // If the user has manually configured a Curl adapter, // configure it for proxy compatibility; otherwise, create // a fresh Proxy adapter. if ( $ this -> hasCurlAdapterAsDefault ( ) ) { $ adapter = new \ Zend \ Http \ Client \ Adapter \ Curl ( ) ; $ this -> setCurlProxyOptions ( $ adapter ) ; } else { $ adapter = new \ Zend \ Http \ Client \ Adapter \ Proxy ( ) ; $ options = array_replace ( $ this -> proxyConfig , $ options ) ; $ adapter -> setOptions ( $ options ) ; } $ client -> setAdapter ( $ adapter ) ; } } } return $ client ; }
Proxify an existing client.

Returns the client given as argument with appropriate proxy setup.

@param \Zend\Http\Client $client  HTTP client
@param array             $options ZF2 ProxyAdapter options

@return \Zend\Http\Client
Proxify an existing client .