Commit ca58f80b authored by Taylor Otwell's avatar Taylor Otwell

removed cache and session factories. moved cache item management into cache...

removed cache and session factories. moved cache item management into cache class and out of drivers. tweaked auth class.
parent ceb0e1a8
...@@ -40,11 +40,9 @@ class Auth { ...@@ -40,11 +40,9 @@ class Auth {
throw new \Exception("You must specify a session driver before using the Auth class."); throw new \Exception("You must specify a session driver before using the Auth class.");
} }
$model = static::model();
if (is_null(static::$user) and Session::has(static::$key)) if (is_null(static::$user) and Session::has(static::$key))
{ {
static::$user = $model::find(Session::get(static::$key)); static::$user = forward_static_call(array(static::model(), 'find'), Session::get(static::$key));
} }
return static::$user; return static::$user;
...@@ -61,9 +59,7 @@ class Auth { ...@@ -61,9 +59,7 @@ class Auth {
*/ */
public static function login($username, $password) public static function login($username, $password)
{ {
$model = static::model(); $model = forward_static_call(array(static::model(), 'where'), Config::get('auth.username'), '=', $username)->first();
$user = $model::where(Config::get('auth.username'), '=', $username)->first();
if ( ! is_null($user)) if ( ! is_null($user))
{ {
......
...@@ -7,7 +7,14 @@ class Cache { ...@@ -7,7 +7,14 @@ class Cache {
* *
* @var Cache\Driver * @var Cache\Driver
*/ */
private static $drivers = array(); public static $drivers = array();
/**
* All of the items retrieved by the cache drivers.
*
* @var array
*/
public static $items = array();
/** /**
* Get a cache driver instance. If no driver name is specified, the default * Get a cache driver instance. If no driver name is specified, the default
...@@ -59,9 +66,9 @@ class Cache { ...@@ -59,9 +66,9 @@ class Cache {
*/ */
public static function get($key, $default = null, $driver = null) public static function get($key, $default = null, $driver = null)
{ {
if (array_key_exists($key, static::driver($driver)->items)) if (isset(static::$items[$driver][$key]))
{ {
return static::driver($driver)->items[$key]; return static::$items[$driver][$key];
} }
if (is_null($item = static::driver($driver)->get($key))) if (is_null($item = static::driver($driver)->get($key)))
...@@ -69,7 +76,7 @@ class Cache { ...@@ -69,7 +76,7 @@ class Cache {
return is_callable($default) ? call_user_func($default) : $default; return is_callable($default) ? call_user_func($default) : $default;
} }
return $item; return static::$items[$driver][$key] = $item;
} }
/** /**
......
<?php namespace System\Cache\Driver; <?php namespace System\Cache\Driver;
class APC implements \System\Cache\Driver { use System\Config;
/** class APC implements \System\Cache\Driver {
* All of the loaded cache items.
*
* @var array
*/
public $items = array();
/** /**
* Determine if an item exists in the cache. * Determine if an item exists in the cache.
...@@ -28,14 +23,7 @@ class APC implements \System\Cache\Driver { ...@@ -28,14 +23,7 @@ class APC implements \System\Cache\Driver {
*/ */
public function get($key) public function get($key)
{ {
$cache = apc_fetch(\System\Config::get('cache.key').$key); return ( ! is_null($cache = apc_fetch(Config::get('cache.key').$key))) ? $cache : null;
if ($cache === false)
{
return null;
}
return $this->items[$key] = $cache;
} }
/** /**
...@@ -48,7 +36,7 @@ class APC implements \System\Cache\Driver { ...@@ -48,7 +36,7 @@ class APC implements \System\Cache\Driver {
*/ */
public function put($key, $value, $minutes) public function put($key, $value, $minutes)
{ {
apc_store(\System\Config::get('cache.key').$key, $value, $minutes * 60); apc_store(Config::get('cache.key').$key, $value, $minutes * 60);
} }
/** /**
...@@ -59,7 +47,7 @@ class APC implements \System\Cache\Driver { ...@@ -59,7 +47,7 @@ class APC implements \System\Cache\Driver {
*/ */
public function forget($key) public function forget($key)
{ {
apc_delete(\System\Config::get('cache.key').$key); apc_delete(Config::get('cache.key').$key);
} }
} }
\ No newline at end of file
...@@ -2,13 +2,6 @@ ...@@ -2,13 +2,6 @@
class File implements \System\Cache\Driver { class File implements \System\Cache\Driver {
/**
* All of the loaded cache items.
*
* @var array
*/
public $items = array();
/** /**
* Determine if an item exists in the cache. * Determine if an item exists in the cache.
* *
...@@ -43,7 +36,7 @@ class File implements \System\Cache\Driver { ...@@ -43,7 +36,7 @@ class File implements \System\Cache\Driver {
return null; return null;
} }
return $this->items[$key] = unserialize(substr($cache, 10)); return unserialize(substr($cache, 10));
} }
/** /**
......
<?php namespace System\Cache\Driver; <?php namespace System\Cache\Driver;
class Memcached implements \System\Cache\Driver { use System\Config;
/** class Memcached implements \System\Cache\Driver {
* All of the loaded cache items.
*
* @var array
*/
public $items = array();
/** /**
* Determine if an item exists in the cache. * Determine if an item exists in the cache.
...@@ -28,14 +23,7 @@ class Memcached implements \System\Cache\Driver { ...@@ -28,14 +23,7 @@ class Memcached implements \System\Cache\Driver {
*/ */
public function get($key) public function get($key)
{ {
$cache = \System\Memcached::instance()->get(\System\Config::get('cache.key').$key); return (($cache = \System\Memcached::instance()->get(Config::get('cache.key').$key)) !== false) ? $cache : null;
if ($cache === false)
{
return null;
}
return $this->items[$key] = $cache;
} }
/** /**
...@@ -48,7 +36,7 @@ class Memcached implements \System\Cache\Driver { ...@@ -48,7 +36,7 @@ class Memcached implements \System\Cache\Driver {
*/ */
public function put($key, $value, $minutes) public function put($key, $value, $minutes)
{ {
\System\Memcached::instance()->set(\System\Config::get('cache.key').$key, $value, 0, $minutes * 60); \System\Memcached::instance()->set(Config::get('cache.key').$key, $value, 0, $minutes * 60);
} }
/** /**
...@@ -59,7 +47,7 @@ class Memcached implements \System\Cache\Driver { ...@@ -59,7 +47,7 @@ class Memcached implements \System\Cache\Driver {
*/ */
public function forget($key) public function forget($key)
{ {
\System\Memcached::instance()->delete(\System\Config::get('cache.key').$key); \System\Memcached::instance()->delete(Config::get('cache.key').$key);
} }
} }
\ No newline at end of file
<?php namespace System\Cache;
class Factory {
/**
* Create a cache driver instance.
*
* @param string $driver
* @return Driver
*/
public static function make($driver)
{
switch ($driver)
{
case 'file':
return new Driver\File;
case 'memcached':
return new Driver\Memcached;
case 'apc':
return new Driver\APC;
default:
throw new \Exception("Cache driver [$driver] is not supported.");
}
}
}
\ No newline at end of file
<?php namespace System\Session;
class Factory {
/**
* Create a session driver instance.
*
* @param string $driver
* @return Driver
*/
public static function make($driver)
{
switch ($driver)
{
case 'file':
return new Driver\File;
case 'db':
return new Driver\DB;
case 'memcached':
return new Driver\Memcached;
case 'apc':
return new Driver\APC;
default:
throw new \Exception("Session driver [$driver] is not supported.");
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment