more refactoring on DI and IoC.

This commit is contained in:
Taylor Otwell
2011-09-20 23:36:13 -05:00
parent 4525eae25a
commit 600e411ad4
10 changed files with 36 additions and 144 deletions

View File

@@ -1,41 +1,15 @@
<?php namespace Laravel\Cache;
use Laravel\Container;
use Laravel\IoC;
class Manager {
/**
* All of the active cache drivers.
*
* @var Cache\Driver
* @var array
*/
public $drivers = array();
/**
* The application IoC container.
*
* @var Container
*/
private $container;
/**
* The default cache driver.
*
* @var string
*/
private $default;
/**
* Create a new cache manager instance.
*
* @param Container $container
* @return void
*/
public function __construct(Container $container, $default)
{
$this->default = $default;
$this->container = $container;
}
protected static $drivers = array();
/**
* Get a cache driver instance.
@@ -46,21 +20,21 @@ class Manager {
* @param string $driver
* @return Cache\Driver
*/
public function driver($driver = null)
public static function driver($driver = null)
{
if (is_null($driver)) $driver = $this->default;
if (is_null($driver)) $driver = Config::get('cache.default');
if ( ! array_key_exists($driver, $this->drivers))
if ( ! array_key_exists($driver, static::$drivers))
{
if ( ! $this->container->registered('laravel.cache.'.$driver))
if ( ! IoC::container()->registered('laravel.cache.'.$driver))
{
throw new \Exception("Cache driver [$driver] is not supported.");
}
return $this->drivers[$driver] = $this->container->resolve('laravel.cache.'.$driver);
return static::$drivers[$driver] = IoC::container()->resolve('laravel.cache.'.$driver);
}
return $this->drivers[$driver];
return static::$drivers[$driver];
}
/**
@@ -69,9 +43,9 @@ class Manager {
* Passing method calls to the driver instance provides a convenient API for the developer
* when always using the default cache driver.
*/
public function __call($method, $parameters)
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array($this->driver(), $method), $parameters);
return call_user_func_array(array(static::driver(), $method), $parameters);
}
}