merge mongo with master

This commit is contained in:
Anton Grebnev
2011-12-05 20:11:20 +04:00
72 changed files with 575 additions and 441 deletions

View File

@ -36,11 +36,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');
}
$config = Config::get(__CLASS__)->$name;
}
if (!is_array($config)) {
throw new Exception('Connection parameters must be an array');
throw new InitializationException('Connection parameters must be an array');
}
$driver = 'MySQLiDriver';
@ -52,7 +55,7 @@ class Db
$connection = new $driver($config);
if (!$connection instanceof DbDriver) {
throw new Exception('Database driver must extends DbDriver');
throw new InitializationException('Database driver must extends DbDriver');
}
self::$connections[$name] = $connection;
}

View File

@ -38,7 +38,7 @@ abstract class DbDriver
$required = array('database', 'username', 'password', 'hostname');
foreach ($required as $option) {
if (!isset($config[$option])) {
throw new Exception('Configuration must have a "' . $option . '".');
throw new GeneralException('Configuration must have a "' . $option . '".');
}
}
}

View File

@ -11,27 +11,27 @@
abstract class DbStatement
{
/**
* @var DbDriver
*/
protected $driver;
/**
* @var string
*/
protected $request;
protected $params = array();
protected $result;
public function __construct($driver, $request)
{
$this->driver = $driver;
$this->request = $request;
$this->driver = $driver;
$this->request = $request;
}
/**
* @param array $params
* @return bool
@ -75,7 +75,7 @@ abstract class DbStatement
}
return $data;
}
/**
* @param string $field
*/
@ -87,26 +87,26 @@ abstract class DbStatement
}
return false;
}
/* Abstract methods */
abstract public function bindParam($param, &$value);
abstract protected function assemble();
abstract public function fetch($style = Db::FETCH_OBJ);
abstract public function fetchObject($class = 'stdClass');
abstract public function close();
/**
* @return int
*/
abstract public function affectedRows();
abstract public function numRows();
/**
* @return bool
*/

View File

@ -80,7 +80,7 @@ class MySQLiDriver extends SqlDbDriver
$port);
// Connection errors check
if (mysqli_connect_error()) {
throw new Exception(mysqli_connect_error(), mysqli_connect_errno());
throw new GeneralException(mysqli_connect_error(), mysqli_connect_errno());
}
$charset = (!empty($this->config['charset'])) ? $this->config['charset'] : 'utf8';

View File

@ -80,7 +80,7 @@ class MySQLiStatement extends DbStatement
/**
* Fetches single row
*
*
* @param mixed $style
* @return mixed
*/
@ -89,7 +89,7 @@ class MySQLiStatement extends DbStatement
if (!$this->result) {
return false;
}
$row = false;
switch ($style) {
case Db::FETCH_OBJ:
@ -105,11 +105,11 @@ class MySQLiStatement extends DbStatement
$row = $this->result->fetch_array(MYSQLI_BOTH);
break;
default:
throw new Exception('Invalid fetch mode "' . $style . '" specified');
throw new GeneralException('Invalid fetch mode "' . $style . '" specified');
}
return $row;
}
/**
* @param string $class
*/
@ -129,7 +129,7 @@ class MySQLiStatement extends DbStatement
}
return $data;
}
public function close()
{
if ($this->result !== null) {
@ -137,12 +137,12 @@ class MySQLiStatement extends DbStatement
$this->result = null;
}
}
public function affectedRows()
{
return $this->driver->getConnection()->affected_rows;
}
public function numRows()
{
if ($this->result) {
@ -150,7 +150,7 @@ class MySQLiStatement extends DbStatement
}
return false;
}
protected function driverExecute($request)
{
/**
@ -166,7 +166,7 @@ class MySQLiStatement extends DbStatement
}
if ($result === false) {
$message = $mysqli->error . "\nQuery: \"" . $request . '"';
throw new Exception($message, $mysqli->errno);
throw new GeneralException($message, $mysqli->errno);
}
if ($result instanceof MySQLi_Result) {
$this->result = $result;