Skip to content

Instantly share code, notes, and snippets.

@reshadman
Created September 8, 2014 07:41
Show Gist options
  • Save reshadman/474ace3c9fa579e5f864 to your computer and use it in GitHub Desktop.
Save reshadman/474ace3c9fa579e5f864 to your computer and use it in GitHub Desktop.
Multiple binding of a class
<?php
class Session {
public function __construct(StorageInterface $storage)
{
$this->storage = $storage;
}
}
class RedisStorage implments StorageInterface {}
class MemcachedStorage implements StorageInterface {}
class Session ServiceProvider extends LaravelServiceProvider {
public function register ()
{
$this->app->bind('session.redis',function($app){
return new Session(new RedisStorage());
});
$this->app->bind('session.memcached',function($app){
return new Session(new MemcachedStorage());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment