Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Container binding improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed Jul 1, 2015
1 parent 931c109 commit 9553089
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/InstagramServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use MetzWeb\Instagram\Instagram;

/**
* This is the Instagram service provider class.
Expand Down Expand Up @@ -56,6 +57,7 @@ public function register()
{
$this->registerFactory($this->app);
$this->registerManager($this->app);
$this->registerBindings($this->app);
}

/**
Expand Down Expand Up @@ -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.
*
Expand All @@ -103,6 +123,7 @@ public function provides()
return [
'instagram',
'instagram.factory',
'instagram.connection',
];
}
}
13 changes: 13 additions & 0 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Vinkla\Tests\Instagram;

use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
use MetzWeb\Instagram\Instagram;
use Vinkla\Instagram\InstagramFactory;
use Vinkla\Instagram\InstagramManager;

Expand All @@ -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);
}
}

0 comments on commit 9553089

Please sign in to comment.