|
@ -10,20 +10,22 @@ |
|
|
* @since 2010-02-16 |
|
|
* @since 2010-02-16 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
namespace Majestic; |
|
|
|
|
|
|
|
|
abstract class Model |
|
|
abstract class Model |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* DbDriver instance |
|
|
* DbDriver instance |
|
|
* |
|
|
* |
|
|
* @var DbDriver |
|
|
|
|
|
|
|
|
* @var \DbDriver |
|
|
*/ |
|
|
*/ |
|
|
protected $db; |
|
|
protected $db; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Cache instance |
|
|
* Cache instance |
|
|
* |
|
|
* |
|
|
* @var Cache |
|
|
|
|
|
|
|
|
* @var \Cache |
|
|
*/ |
|
|
*/ |
|
|
protected $cache; |
|
|
protected $cache; |
|
|
|
|
|
|
|
@ -48,7 +50,7 @@ abstract class Model |
|
|
|
|
|
|
|
|
public function __construct($connection = 'default') |
|
|
public function __construct($connection = 'default') |
|
|
{ |
|
|
{ |
|
|
$this->db = Db::connect($connection); |
|
|
|
|
|
|
|
|
$this->db = \Majestic\Db::connect($connection); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -94,12 +96,12 @@ abstract class Model |
|
|
/* Cache workaround */ |
|
|
/* Cache workaround */ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @return Cache |
|
|
|
|
|
|
|
|
* @return \Cache |
|
|
*/ |
|
|
*/ |
|
|
public function getCache() |
|
|
public function getCache() |
|
|
{ |
|
|
{ |
|
|
if (!$this->cache) { |
|
|
if (!$this->cache) { |
|
|
$this->cache = Cacher::get(Config::get(__CLASS__, 'MemcacheCache')); |
|
|
|
|
|
|
|
|
$this->cache = \Cacher::get(Config::get(__CLASS__, 'MemcacheCache')); |
|
|
} |
|
|
} |
|
|
return $this->cache; |
|
|
return $this->cache; |
|
|
} |
|
|
} |
|
@ -107,16 +109,16 @@ abstract class Model |
|
|
/** |
|
|
/** |
|
|
* @param string $name |
|
|
* @param string $name |
|
|
* @param array $params |
|
|
* @param array $params |
|
|
* @return CacheKey |
|
|
|
|
|
|
|
|
* @return \CacheKey |
|
|
*/ |
|
|
*/ |
|
|
protected function cacheKey($name, $params = array()) |
|
|
protected function cacheKey($name, $params = array()) |
|
|
{ |
|
|
{ |
|
|
$expire = (isset($this->cache_keys[$name])) ? ($this->cache_keys[$name] * 60) : 0; |
|
|
$expire = (isset($this->cache_keys[$name])) ? ($this->cache_keys[$name] * 60) : 0; |
|
|
return new CacheKey($this->getCache(), $name, $params, $expire); |
|
|
|
|
|
|
|
|
return new \CacheKey($this->getCache(), $name, $params, $expire); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param CacheKey $cache |
|
|
|
|
|
|
|
|
* @param \CacheKey $cache |
|
|
*/ |
|
|
*/ |
|
|
protected function addCleanCache($cache) |
|
|
protected function addCleanCache($cache) |
|
|
{ |
|
|
{ |
|
@ -152,21 +154,21 @@ abstract class Model |
|
|
* @param string $data Request |
|
|
* @param string $data Request |
|
|
* @param array $params Request parameters |
|
|
* @param array $params Request parameters |
|
|
* @param string $field Requested field name |
|
|
* @param string $field Requested field name |
|
|
* @param CacheKey $cache_key Key for caching in |
|
|
|
|
|
|
|
|
* @param \CacheKey $cache_key Key for caching in |
|
|
*/ |
|
|
*/ |
|
|
abstract protected function fetchField($data, $params = array(), $field, $cache_key = null); |
|
|
abstract protected function fetchField($data, $params = array(), $field, $cache_key = null); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param string $data Request |
|
|
* @param string $data Request |
|
|
* @param array $params Request parameters |
|
|
* @param array $params Request parameters |
|
|
* @param CacheKey $cache_key Key for caching in |
|
|
|
|
|
|
|
|
* @param \CacheKey $cache_key Key for caching in |
|
|
*/ |
|
|
*/ |
|
|
abstract protected function fetch($data, $params = array(), $cache_key = null); |
|
|
abstract protected function fetch($data, $params = array(), $cache_key = null); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param string $data |
|
|
* @param string $data |
|
|
* @param array $params |
|
|
* @param array $params |
|
|
* @param CacheKey $cache_key |
|
|
|
|
|
|
|
|
* @param \CacheKey $cache_key |
|
|
*/ |
|
|
*/ |
|
|
abstract protected function fetchAll($data, $params = array(), $cache_key = null); |
|
|
abstract protected function fetchAll($data, $params = array(), $cache_key = null); |
|
|
} |
|
|
} |