removed cache and session factories. moved cache item management into cache class and out of drivers. tweaked auth class.
This commit is contained in:
parent
ceb0e1a807
commit
ca58f80b22
|
@ -40,11 +40,9 @@ public static function user()
|
||||||
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 @@ public static function user()
|
||||||
*/
|
*/
|
||||||
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 {
|
||||||
*
|
*
|
||||||
* @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 @@ public static function driver($driver = null)
|
||||||
*/
|
*/
|
||||||
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 @@ public static function get($key, $default = null, $driver = null)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
<?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 @@ public function has($key)
|
||||||
*/
|
*/
|
||||||
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 @@ public function get($key)
|
||||||
*/
|
*/
|
||||||
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 @@ public function put($key, $value, $minutes)
|
||||||
*/
|
*/
|
||||||
public function forget($key)
|
public function forget($key)
|
||||||
{
|
{
|
||||||
apc_delete(\System\Config::get('cache.key').$key);
|
apc_delete(Config::get('cache.key').$key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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 @@ public function get($key)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->items[$key] = unserialize(substr($cache, 10));
|
return unserialize(substr($cache, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
<?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 @@ public function has($key)
|
||||||
*/
|
*/
|
||||||
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 @@ public function get($key)
|
||||||
*/
|
*/
|
||||||
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 @@ public function put($key, $value, $minutes)
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
<?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.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
<?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.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue