Make guzzle client use the proxy configuration when injected by the ioc
authorymh <ymh.work@gmail.com>
Sat, 10 Jun 2017 17:57:34 +0200
changeset 533 a557802f2b12
parent 532 1190ea937f2d
child 534 8551ee315a41
Make guzzle client use the proxy configuration when injected by the ioc
server/src/app/Providers/GuzzleServiceProvider.php
--- a/server/src/app/Providers/GuzzleServiceProvider.php	Sat Jun 10 08:33:03 2017 +0200
+++ b/server/src/app/Providers/GuzzleServiceProvider.php	Sat Jun 10 17:57:34 2017 +0200
@@ -10,6 +10,13 @@
  */
 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
      *
@@ -17,9 +24,7 @@
      */
     public function register()
     {
-        $this->app->bind('Guzzle', function() {
-            $config = isset($this->app['config']['guzzle']) ? $this->app['config']['guzzle'] : [];
-            return new Client($config);
-        });
+        $this->bindToKey('Guzzle');
+        $this->bindToKey('GuzzleHttp\Client');
     }
 }