server/src/app/Providers/GuzzleServiceProvider.php
author ymh <ymh.work@gmail.com>
Sat, 10 Jun 2017 17:57:34 +0200
changeset 533 a557802f2b12
parent 139 8d688175513a
permissions -rw-r--r--
Make guzzle client use the proxy configuration when injected by the ioc

<?php

namespace CorpusParole\Providers;

use Illuminate\Support\ServiceProvider;
use GuzzleHttp\Client;

/**
 * guzzle Service Provider, inspired by https://github.com/urakozz/laravel-guzzle
 */
class GuzzleServiceProvider extends ServiceProvider
{

    private function bindToKey($key) {
        $this->app->bind($key, function() {
            $config = isset($this->app['config']['guzzle']) ? $this->app['config']['guzzle'] : [];
            return new Client($config);
        });
    }
    /**
     * Register the Guzzle provider
     *
     * @return GuzzleClient
     */
    public function register()
    {
        $this->bindToKey('Guzzle');
        $this->bindToKey('GuzzleHttp\Client');
    }
}