Files
spa-api/laravel/cache/manager.php

51 lines
1.2 KiB
PHP
Raw Normal View History

<?php namespace Laravel\Cache;
2011-08-18 19:56:29 -05:00
2011-09-20 23:36:13 -05:00
use Laravel\IoC;
class Manager {
2011-08-18 19:56:29 -05:00
/**
* All of the active cache drivers.
*
2011-09-20 23:36:13 -05:00
* @var array
2011-08-18 19:56:29 -05:00
*/
2011-09-20 23:36:13 -05:00
protected static $drivers = array();
2011-08-18 19:56:29 -05:00
/**
* Get a cache driver instance.
*
* If no driver name is specified, the default cache driver will be returned
* as defined in the cache configuration file.
*
* @param string $driver
* @return Cache\Driver
*/
2011-09-20 23:36:13 -05:00
public static function driver($driver = null)
2011-08-18 19:56:29 -05:00
{
2011-09-20 23:36:13 -05:00
if (is_null($driver)) $driver = Config::get('cache.default');
2011-08-18 19:56:29 -05:00
2011-09-20 23:36:13 -05:00
if ( ! array_key_exists($driver, static::$drivers))
2011-08-18 19:56:29 -05:00
{
2011-09-20 23:36:13 -05:00
if ( ! IoC::container()->registered('laravel.cache.'.$driver))
2011-08-18 19:56:29 -05:00
{
throw new \Exception("Cache driver [$driver] is not supported.");
2011-08-18 19:56:29 -05:00
}
2011-09-20 23:36:13 -05:00
return static::$drivers[$driver] = IoC::container()->resolve('laravel.cache.'.$driver);
2011-08-18 19:56:29 -05:00
}
2011-09-20 23:36:13 -05:00
return static::$drivers[$driver];
2011-08-18 19:56:29 -05:00
}
/**
2011-08-19 20:12:39 -05:00
* Pass all other methods to the default cache driver.
2011-08-18 19:56:29 -05:00
*
* Passing method calls to the driver instance provides a convenient API for the developer
* when always using the default cache driver.
*/
2011-09-20 23:36:13 -05:00
public static function __callStatic($method, $parameters)
2011-08-18 19:56:29 -05:00
{
2011-09-20 23:36:13 -05:00
return call_user_func_array(array(static::driver(), $method), $parameters);
2011-08-18 19:56:29 -05:00
}
}