cnerta/behind-a-proxy-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Add proxy parameters for CURL, SoapClient connection and PHP function using stream context.

Maintainers

Package info

github.com/AgrosupDijon-Eduter/BehindAProxyBundle

Issues

Type:symfony-bundle

pkg:composer/cnerta/behind-a-proxy-bundle

Statistics

Installs: 542

Dependents: 0

Suggesters: 0

Stars: 2

2.0.1 2016-04-13 07:10 UTC

This package is not auto-updated.

Last update: 2020-02-02 16:31:22 UTC


README

Cnerta Behind A Proxy Bundle

Add proxy parameters for CURL, SoapClient connection and PHP function using stream context.

SensioLabsInsight

Build Status Latest Stable Version Latest Unstable Version

WARNING host_ssl configuration has been removed since version 2.0.0
For PHP 5.4 and below, please use the version 1 of the bundle

Install the Bundle

  1. Add the sources in your composer.json
     "require": {
        // ...
        "cnerta/behind-a-proxy-bundle": "1.0.*"
    }
  1. Then add it to your AppKernel class::
    // in AppKernel::registerBundles()
    $bundles = array(
        // ...
        new Cnerta\BehindAProxyBundle\CnertaBehindAProxyBundle(),
        // ...
    );

Configuration

config.yml

    cnerta_behind_a_proxy:
        enabled: false                # type: boulean, default value: false, desc: enabled (true), or desabled (false) the use of proxy
        host: 127.0.0.1               # type: string, default value: null, desc : this is the IP or URL of the proxy server
        port: 80                      # type: mixed(string|int), default value: null, desc : this is the port of the proxy server
        login: myWonderfulLogin       # type: string, default value: null, desc : this is the login for authentication against the proxy server
        password: myWonderfulLogin    # type: string, default value: null, this is the password for authentication against the proxy server
        load_default_stream_context: false    # type: boolean, default value: false, If you need to set the default proxy config global
        http:       # Option set only for http request
            host_proxy: 127.0.0.1     # type: string, default value: null, desc : this is the IP or URL of the proxy server
            port_proxy: 80            # type: mixed(string|int), default value: null, desc : this is the port of the proxy server
            login_proxy: login        # type: string, default value: null, desc : this is the login for authentication against the proxy server
            password_proxy: password  # type: string, default value: null, this is the password for authentication against the proxy server
            request_fulluri: true     # type: boulean, default value: false, desc: enabled (true), or desabled (false) the full uri option of context
        https:      # Option set only for https request
            host_proxy: 127.0.0.1     # type: string, default value: null, desc : this is the IP or URL of the proxy server
            port_proxy: 80            # type: mixed(string|int), default value: null, desc : this is the port of the proxy server
            login_proxy: login        # type: string, default value: null, desc : this is the login for authentication against the proxy server
            password_proxy: password  # type: string, default value: null, this is the password for authentication against the proxy server
            request_fulluri: true     # type: boulean, default value: false, desc: enabled (true), or desabled (false) the full uri option of context

Set configuration proxy for CURL

    use Symfony\Component\DependencyInjection\ContainerInterface;
    /**
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
     */
    private $container;

    //...

    $s = curl_init();
    curl_setopt($s, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($s, CURLOPT_FAILONERROR, true);
    curl_setopt($s, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($s, CURLOPT_URL, $this->url);

    // Call cnerta.baproxy service and call the method setProxyForCURL
    // the CURL resource '$s' is passed by reference
    $container->get('cnerta.baproxy')->setProxyForCURL($s);

    curl_exec($s);
    $status = curl_getinfo($s, CURLINFO_HTTP_CODE);
    $error = curl_error($s);

    curl_close($s);

    if ($status == 401) {
        throw new \RuntimeException("Invalid Credencial to connect to WebService");
    } else if ($status == 404) {
        throw new \RuntimeException("Invalid URL to connect to WebService");
    } elseif ($status != 200) {
        throw new \RuntimeException($error);
    }

Set configuration proxy for SoapClient


    use Symfony\Component\DependencyInjection\ContainerInterface;
    /**
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
     */
    private $container;

    //...

    $config =  array(
        "trace" => true,
        "exceptions" => 0,
        "cache_wsdl" => WSDL_CACHE_NONE
    );

    $container->get('cnerta.baproxy')->setProxyForSoapClient($config);

    $soapClient = new \SoapClient('http://www.somewhere.com/?wsdl', $config);

Get Parameters anywhere

    use Symfony\Component\DependencyInjection\ContainerInterface;
    /**
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
     */
    private $container;

    //...

    $this->container->getParameter("cnerta_baproxy.enabled")
    $this->container->getParameter("cnerta_baproxy.host")
    $this->container->getParameter("cnerta_baproxy.port")
    $this->container->getParameter("cnerta_baproxy.host_ssl")
    $this->container->getParameter("cnerta_baproxy.login")
    $this->container->getParameter("cnerta_baproxy.password")
    $this->container->getParameter("cnerta_baproxy.http")
    $this->container->getParameter("cnerta_baproxy.https")