1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 05:37:39 +02:00

added DibiRow::toArray() & Countable

This commit is contained in:
David Grudl
2010-04-26 20:44:17 +02:00
parent 26384626ba
commit 5d95f0ba0d
2 changed files with 20 additions and 6 deletions

View File

@@ -398,7 +398,7 @@ class DibiResult extends DibiObject implements IDataSource
} elseif ($as === '=') { // "record" node
if ($x === NULL) {
$x = (array) $row;
$x = $row->toArray();
$x = & $x[ $assoc[$i+1] ];
$x = NULL; // prepare child node
} else {
@@ -422,7 +422,7 @@ class DibiResult extends DibiObject implements IDataSource
if ($x === NULL) { // build leaf
if ($leaf === '=') {
$x = (array) $row;
$x = $row->toArray();
} else {
$x = $row;
}
@@ -457,7 +457,7 @@ class DibiResult extends DibiObject implements IDataSource
}
// autodetect
$tmp = array_keys((array) $row);
$tmp = array_keys($row->toArray());
$key = $tmp[0];
if (count($row) < 2) { // indexed-array
do {

View File

@@ -18,16 +18,23 @@
* @copyright Copyright (c) 2005, 2010 David Grudl
* @package dibi
*/
class DibiRow implements ArrayAccess, IteratorAggregate
class DibiRow implements ArrayAccess, IteratorAggregate, Countable
{
function __construct($arr)
public function __construct($arr)
{
foreach ($arr as $k => $v) $this->$k = $v;
}
public function toArray()
{
return (array) $this;
}
/**
* Converts value to DateTime object.
* @param string key
@@ -91,7 +98,14 @@ class DibiRow implements ArrayAccess, IteratorAggregate
/********************* interfaces ArrayAccess & IteratorAggregate ****************d*g**/
/********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/
final public function count()
{
return count((array) $this);
}