continued ioc refactoring.
This commit is contained in:
18
laravel/cache/apc.php
vendored
18
laravel/cache/apc.php
vendored
@@ -1,7 +1,5 @@
|
||||
<?php namespace Laravel\Cache;
|
||||
|
||||
use Laravel\Config;
|
||||
|
||||
/**
|
||||
* Wrap the APC functions in a class that can be injected into driver.
|
||||
* Since the APC functions are global, the driver is untestable without
|
||||
@@ -55,15 +53,23 @@ class APC extends Driver {
|
||||
*/
|
||||
private $apc;
|
||||
|
||||
/**
|
||||
* The cache key from the cache configuration file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* Create a new APC cache driver instance.
|
||||
*
|
||||
* @param APC_Engine $apc
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(APC_Engine $apc)
|
||||
public function __construct(APC_Engine $apc, $key)
|
||||
{
|
||||
$this->apc = $apc;
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +96,7 @@ class APC extends Driver {
|
||||
*/
|
||||
protected function retrieve($key)
|
||||
{
|
||||
return ( ! is_null($cache = $this->apc->get(Config::get('cache.key').$key))) ? $cache : null;
|
||||
return ( ! is_null($cache = $this->apc->get($this->key.$key))) ? $cache : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +114,7 @@ class APC extends Driver {
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->apc->put(Config::get('cache.key').$key, $value, $minutes * 60);
|
||||
$this->apc->put($this->key.$key, $value, $minutes * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +125,7 @@ class APC extends Driver {
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$this->apc->forget(Config::get('cache.key').$key);
|
||||
$this->apc->forget($this->key.$key);
|
||||
}
|
||||
|
||||
}
|
||||
19
laravel/cache/file.php
vendored
19
laravel/cache/file.php
vendored
@@ -9,15 +9,24 @@ class File extends Driver {
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* The path to which the cache files should be written.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* Create a new File cache driver instance.
|
||||
*
|
||||
* @param Laravel\File $file
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(\Laravel\File $file)
|
||||
public function __construct(\Laravel\File $file, $path)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,9 +53,9 @@ class File extends Driver {
|
||||
*/
|
||||
protected function retrieve($key)
|
||||
{
|
||||
if ( ! $this->file->exists(CACHE_PATH.$key)) return null;
|
||||
if ( ! $this->file->exists($this->path.$key)) return null;
|
||||
|
||||
if (time() >= substr($cache = $this->file->get(CACHE_PATH.$key), 0, 10))
|
||||
if (time() >= substr($cache = $this->file->get($this->path.$key), 0, 10))
|
||||
{
|
||||
return $this->forget($key);
|
||||
}
|
||||
@@ -69,7 +78,7 @@ class File extends Driver {
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->file->put(CACHE_PATH.$key, (time() + ($minutes * 60)).serialize($value));
|
||||
$this->file->put($this->path.$key, (time() + ($minutes * 60)).serialize($value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +89,7 @@ class File extends Driver {
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$this->file->delete(CACHE_PATH.$key);
|
||||
$this->file->delete($this->path.$key);
|
||||
}
|
||||
|
||||
}
|
||||
51
laravel/cache/manager.php
vendored
51
laravel/cache/manager.php
vendored
@@ -1,7 +1,6 @@
|
||||
<?php namespace Laravel\Cache;
|
||||
|
||||
use Laravel\IoC;
|
||||
use Laravel\Config;
|
||||
use Laravel\Container;
|
||||
|
||||
class Manager {
|
||||
|
||||
@@ -10,7 +9,33 @@ class Manager {
|
||||
*
|
||||
* @var Cache\Driver
|
||||
*/
|
||||
public static $drivers = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a cache driver instance.
|
||||
@@ -20,30 +45,30 @@ class Manager {
|
||||
*
|
||||
* <code>
|
||||
* // Get the default cache driver
|
||||
* $driver = Cache::driver();
|
||||
* $driver = $application->cache->driver();
|
||||
*
|
||||
* // Get the APC cache driver
|
||||
* $apc = Cache::driver('apc');
|
||||
* $apc = $application->cache->driver('apc');
|
||||
* </code>
|
||||
*
|
||||
* @param string $driver
|
||||
* @return Cache\Driver
|
||||
*/
|
||||
public static function driver($driver = null)
|
||||
public function driver($driver = null)
|
||||
{
|
||||
if (is_null($driver)) $driver = Config::get('cache.driver');
|
||||
if (is_null($driver)) $driver = $this->default;
|
||||
|
||||
if ( ! array_key_exists($driver, static::$drivers))
|
||||
if ( ! array_key_exists($driver, $this->drivers))
|
||||
{
|
||||
if ( ! in_array($driver, array('apc', 'file', 'memcached')))
|
||||
{
|
||||
throw new \Exception("Cache driver [$driver] is not supported.");
|
||||
}
|
||||
|
||||
return static::$drivers[$driver] = IoC::container()->resolve('laravel.cache.'.$driver);
|
||||
return $this->drivers[$driver] = $this->container->resolve('laravel.cache.'.$driver);
|
||||
}
|
||||
|
||||
return static::$drivers[$driver];
|
||||
return $this->drivers[$driver];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,12 +79,12 @@ class Manager {
|
||||
*
|
||||
* <code>
|
||||
* // Get an item from the default cache driver
|
||||
* $name = Cache::get('name');
|
||||
* $name = $application->cache->get('name');
|
||||
* </code>
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return call_user_func_array(array(static::driver(), $method), $parameters);
|
||||
return call_user_func_array(array($this->driver(), $method), $parameters);
|
||||
}
|
||||
|
||||
}
|
||||
17
laravel/cache/memcached.php
vendored
17
laravel/cache/memcached.php
vendored
@@ -1,5 +1,6 @@
|
||||
<?php namespace Laravel\Cache;
|
||||
|
||||
use Memcache;
|
||||
use Laravel\Config;
|
||||
|
||||
class Memcached extends Driver {
|
||||
@@ -11,14 +12,22 @@ class Memcached extends Driver {
|
||||
*/
|
||||
private $memcache;
|
||||
|
||||
/**
|
||||
* The cache key from the cache configuration file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* Create a new Memcached cache driver instance.
|
||||
*
|
||||
* @param Memcache $memcache
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(\Memcache $memcache)
|
||||
public function __construct(Memcache $memcache, $key)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->memcache = $memcache;
|
||||
}
|
||||
|
||||
@@ -46,7 +55,7 @@ class Memcached extends Driver {
|
||||
*/
|
||||
protected function retrieve($key)
|
||||
{
|
||||
return (($cache = $this->memcache->get(Config::get('cache.key').$key)) !== false) ? $cache : null;
|
||||
return (($cache = $this->memcache->get($this->key.$key)) !== false) ? $cache : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +73,7 @@ class Memcached extends Driver {
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->memcache->set(Config::get('cache.key').$key, $value, 0, $minutes * 60);
|
||||
$this->memcache->set($this->key.$key, $value, 0, $minutes * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +84,7 @@ class Memcached extends Driver {
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$this->memcache->delete(Config::get('cache.key').$key);
|
||||
$this->memcache->delete($this->key.$key);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user