1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-12 00:54:11 +02:00

- added configuration option 'resultClass'

- updated class Object
This commit is contained in:
David Grudl
2008-08-28 02:02:21 +00:00
parent 119d5a1995
commit 360f8799cf
3 changed files with 38 additions and 17 deletions

View File

@@ -53,6 +53,12 @@ class DibiConnection extends /*Nette::*/Object
*/
private $inTxn = FALSE;
/**
* Result set encapsulation.
* @var string
*/
private $resultClass = 'DibiResult';
/**
@@ -103,12 +109,18 @@ class DibiConnection extends /*Nette::*/Object
unset($config['result:objects']);
}
if (isset($config['resultObjects'])) {
// normalize
if (isset($config['resultObjects'])) { // normalize
$val = $config['resultObjects'];
$config['resultObjects'] = is_string($val) && !is_numeric($val) ? $val : (bool) $val;
}
if (isset($config['resultClass'])) {
if (strcasecmp($config['resultClass'], 'DibiResult') && !is_subclass_of($config['resultClass'], 'DibiResult')) {
throw new InvalidArgumentException("Class '$config[resultClass]' is not DibiResult descendant.");
}
$this->resultClass = $config['resultClass'];
}
$config['name'] = $name;
$this->config = $config;
$this->driver = new $class;
@@ -294,7 +306,7 @@ class DibiConnection extends /*Nette::*/Object
dibi::notify($this, 'beforeQuery', $sql);
if ($res = $this->driver->query($sql)) { // intentionally =
$res = new DibiResult($res, $this->config);
$res = new $this->resultClass($res, $this->config);
}
$time += microtime(TRUE);

View File

@@ -21,7 +21,7 @@
/**
* dibi result-set abstract class.
* dibi result-set.
*
* <code>
* $result = dibi::query('SELECT * FROM [table]');
@@ -288,7 +288,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource
*
* @return mixed value on success, FALSE if no next record
*/
final function fetchSingle()
final public function fetchSingle()
{
$row = $this->getDriver()->fetch(TRUE);
if (!is_array($row)) return FALSE;
@@ -315,7 +315,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource
* @param bool simplify one-column result set?
* @return array
*/
final function fetchAll($offset = NULL, $limit = NULL, $simplify = TRUE)
final public function fetchAll($offset = NULL, $limit = NULL, $simplify = TRUE)
{
$limit = $limit === NULL ? -1 : (int) $limit;
$this->seek((int) $offset);
@@ -354,7 +354,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource
* @return array
* @throws InvalidArgumentException
*/
final function fetchAssoc($assoc)
final public function fetchAssoc($assoc)
{
$this->seek(0);
$row = $this->fetch(FALSE);
@@ -437,7 +437,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource
* @return array
* @throws InvalidArgumentException
*/
final function fetchPairs($key = NULL, $value = NULL)
final public function fetchPairs($key = NULL, $value = NULL)
{
$this->seek(0);
$row = $this->fetch(FALSE);