From 95530895bdd1af59ce35b3bd6a310c712593cd9e Mon Sep 17 00:00:00 2001 From: Vincent Klaiber Date: Wed, 1 Jul 2015 08:47:38 +0200 Subject: [PATCH] Container binding improvements --- src/InstagramServiceProvider.php | 21 +++++++++++++++++++++ tests/ServiceProviderTest.php | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/InstagramServiceProvider.php b/src/InstagramServiceProvider.php index 40a44a4..4c1355d 100644 --- a/src/InstagramServiceProvider.php +++ b/src/InstagramServiceProvider.php @@ -13,6 +13,7 @@ use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\ServiceProvider; +use MetzWeb\Instagram\Instagram; /** * This is the Instagram service provider class. @@ -56,6 +57,7 @@ public function register() { $this->registerFactory($this->app); $this->registerManager($this->app); + $this->registerBindings($this->app); } /** @@ -93,6 +95,24 @@ protected function registerManager(Application $app) $app->alias('instagram', InstagramManager::class); } + /** + * Register the bindings. + * + * @param \Illuminate\Contracts\Foundation\Application $app + * + * @return void + */ + protected function registerBindings(Application $app) + { + $app->bind('instagram.connection', function ($app) { + $manager = $app['instagram']; + + return $manager->connection(); + }); + + $app->alias('instagram.connection', Instagram::class); + } + /** * Get the services provided by the provider. * @@ -103,6 +123,7 @@ public function provides() return [ 'instagram', 'instagram.factory', + 'instagram.connection', ]; } } diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 5db4364..b511ef8 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -12,6 +12,7 @@ namespace Vinkla\Tests\Instagram; use GrahamCampbell\TestBenchCore\ServiceProviderTrait; +use MetzWeb\Instagram\Instagram; use Vinkla\Instagram\InstagramFactory; use Vinkla\Instagram\InstagramManager; @@ -33,4 +34,16 @@ public function testInstagramManagerIsInjectable() { $this->assertIsInjectable(InstagramManager::class); } + + public function testBindings() + { + $this->assertIsInjectable(Instagram::class); + + $original = $this->app['instagram.connection']; + $this->app['instagram']->reconnect(); + $new = $this->app['instagram.connection']; + + $this->assertNotSame($original, $new); + $this->assertEquals($original, $new); + } }