server/src/app/Providers/GuzzleServiceProvider.php
changeset 533 a557802f2b12
parent 139 8d688175513a
equal deleted inserted replaced
532:1190ea937f2d 533:a557802f2b12
     8 /**
     8 /**
     9  * guzzle Service Provider, inspired by https://github.com/urakozz/laravel-guzzle
     9  * guzzle Service Provider, inspired by https://github.com/urakozz/laravel-guzzle
    10  */
    10  */
    11 class GuzzleServiceProvider extends ServiceProvider
    11 class GuzzleServiceProvider extends ServiceProvider
    12 {
    12 {
       
    13 
       
    14     private function bindToKey($key) {
       
    15         $this->app->bind($key, function() {
       
    16             $config = isset($this->app['config']['guzzle']) ? $this->app['config']['guzzle'] : [];
       
    17             return new Client($config);
       
    18         });
       
    19     }
    13     /**
    20     /**
    14      * Register the Guzzle provider
    21      * Register the Guzzle provider
    15      *
    22      *
    16      * @return GuzzleClient
    23      * @return GuzzleClient
    17      */
    24      */
    18     public function register()
    25     public function register()
    19     {
    26     {
    20         $this->app->bind('Guzzle', function() {
    27         $this->bindToKey('Guzzle');
    21             $config = isset($this->app['config']['guzzle']) ? $this->app['config']['guzzle'] : [];
    28         $this->bindToKey('GuzzleHttp\Client');
    22             return new Client($config);
       
    23         });
       
    24     }
    29     }
    25 }
    30 }