Commit with composer.json

This commit is contained in:
2014-05-27 17:56:46 +04:00
parent c62620593f
commit aec1a60985
20 changed files with 70 additions and 46 deletions

View File

@ -7,6 +7,8 @@
* @since 2010-02-16
*/
namespace Majestic;
class Db
{
@ -35,14 +37,14 @@ class Db
{
if (!isset(self::$connections[$name])) {
if (!$config) {
if (!is_object(Config::get(__CLASS__))) {
throw new InitializationException('Trying to get property of non-object');
if (!is_object(\Majestic\Config::get(__CLASS__))) {
throw new \InitializationException('Trying to get property of non-object');
}
$config = Config::get(__CLASS__)->$name;
$config = \Majestic\Config::get(__CLASS__)->$name;
}
if (!is_array($config)) {
throw new InitializationException('Connection parameters must be an array');
throw new \InitializationException('Connection parameters must be an array');
}
$driver = 'MySQLiDriver';
@ -53,8 +55,8 @@ class Db
$connection = new $driver($config);
if (!$connection instanceof DbDriver) {
throw new InitializationException('Database driver must extends DbDriver');
if (!$connection instanceof \DbDriver) {
throw new \InitializationException('Database driver must extends DbDriver');
}
self::$connections[$name] = $connection;
}

View File

@ -53,7 +53,7 @@ abstract class DbStatement
* @param mixed $style
* @return array
*/
public function fetchAll($style = Db::FETCH_OBJ)
public function fetchAll($style = \Majestic\Db::FETCH_OBJ)
{
$data = array();
while ($row = $this->fetch($style)) {
@ -69,7 +69,7 @@ abstract class DbStatement
public function fetchColumn($field)
{
$data = array();
while ($row = $this->fetch(Db::FETCH_ASSOC)) {
while ($row = $this->fetch(\Majestic\Db::FETCH_ASSOC)) {
$data[] = $row[$field];
}
return $data;
@ -81,7 +81,7 @@ abstract class DbStatement
*/
public function fetchField($field)
{
$row = $this->fetch(Db::FETCH_ASSOC);
$row = $this->fetch(\Majestic\Db::FETCH_ASSOC);
if (isset($row[$field])) {
return $row[$field];
}
@ -94,7 +94,7 @@ abstract class DbStatement
abstract protected function assemble();
abstract public function fetch($style = Db::FETCH_OBJ);
abstract public function fetch($style = \Majestic\Db::FETCH_OBJ);
abstract public function fetchObject($class = 'stdClass');

View File

@ -10,20 +10,22 @@
* @since 2010-02-16
*/
namespace Majestic;
abstract class Model
{
/**
* DbDriver instance
*
* @var DbDriver
* @var \DbDriver
*/
protected $db;
/**
* Cache instance
*
* @var Cache
* @var \Cache
*/
protected $cache;
@ -48,7 +50,7 @@ abstract class Model
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 */
/**
* @return Cache
* @return \Cache
*/
public function getCache()
{
if (!$this->cache) {
$this->cache = Cacher::get(Config::get(__CLASS__, 'MemcacheCache'));
$this->cache = \Cacher::get(Config::get(__CLASS__, 'MemcacheCache'));
}
return $this->cache;
}
@ -107,16 +109,16 @@ abstract class Model
/**
* @param string $name
* @param array $params
* @return CacheKey
* @return \CacheKey
*/
protected function cacheKey($name, $params = array())
{
$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)
{
@ -152,21 +154,21 @@ abstract class Model
* @param string $data Request
* @param array $params Request parameters
* @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);
/**
* @param string $data Request
* @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);
/**
* @param string $data
* @param array $params
* @param CacheKey $cache_key
* @param \CacheKey $cache_key
*/
abstract protected function fetchAll($data, $params = array(), $cache_key = null);
}

View File

@ -83,23 +83,23 @@ class MySQLiStatement extends DbStatement
* @return mixed
* @throws GeneralException
*/
public function fetch($style = Db::FETCH_OBJ)
public function fetch($style = \Majestic\Db::FETCH_OBJ)
{
if (!$this->result) {
return false;
}
switch ($style) {
case Db::FETCH_OBJ:
case \Majestic\Db::FETCH_OBJ:
$row = $this->result->fetch_object();
break;
case Db::FETCH_NUM:
case \Majestic\Db::FETCH_NUM:
$row = $this->result->fetch_array(MYSQLI_NUM);
break;
case Db::FETCH_ASSOC:
case \Majestic\Db::FETCH_ASSOC:
$row = $this->result->fetch_assoc();
break;
case Db::FETCH_BOTH:
case \Majestic\Db::FETCH_BOTH:
$row = $this->result->fetch_array(MYSQLI_BOTH);
break;
default:
@ -123,7 +123,7 @@ class MySQLiStatement extends DbStatement
public function fetchPairs()
{
$data = array();
while ($row = $this->fetch(Db::FETCH_NUM)) {
while ($row = $this->fetch(\Majestic\Db::FETCH_NUM)) {
$data[$row[0]] = $row[1];
}
return $data;

View File

@ -13,7 +13,7 @@
/**
* @property SqlDbDriver $db
*/
abstract class SqlModel extends Model
abstract class SqlModel extends \Majestic\Model
{
/**
* @param string $ident