diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index a94b1543..5b04a56d 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -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 { diff --git a/dibi/libs/DibiRow.php b/dibi/libs/DibiRow.php index b0867f17..0d422a94 100644 --- a/dibi/libs/DibiRow.php +++ b/dibi/libs/DibiRow.php @@ -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); + }