From 52d2ecf5b061cf6f0122b65fe0614dc642334128 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 3 Sep 2008 22:47:49 +0000 Subject: [PATCH] - DibiResult::fetchAssoc() respects 'resultObject' configuration option - DibiResult::dump() forces arrays - updated Nette::Object --- dibi/Nette/Object.php | 20 ++++++++++++++------ dibi/libs/DibiResult.php | 21 ++++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/dibi/Nette/Object.php b/dibi/Nette/Object.php index 406faba0..42eb64ce 100644 --- a/dibi/Nette/Object.php +++ b/dibi/Nette/Object.php @@ -108,14 +108,22 @@ abstract class Object } // event functionality - if (property_exists($class, $name) && preg_match('#^on[A-Z]#', $name)) { - $list = $this->$name; - if (is_array($list) || $list instanceof Traversable) { - foreach ($list as $handler) { - call_user_func_array($handler, $args); + if (preg_match('#^on[A-Z]#', $name)) { + $rp = new ReflectionProperty($class, $name); + if ($rp->isPublic() && !$rp->isStatic()) { + $list = $this->$name; + if (is_array($list) || $list instanceof Traversable) { + foreach ($list as $handler) { + /**/if (is_object($handler)) { + call_user_func_array(array($handler, '__invoke'), $args); + + } else /**/{ + call_user_func_array($handler, $args); + } + } } + return; } - return; } // extension methods diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index 5c4ceb91..6a1bbfa7 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -371,7 +371,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource } // strip leading = and @ - $assoc[] = '='; // gap + $leaf = $this->objects ? $this->objects : '='; // gap $last = count($assoc) - 1; while ($assoc[$last] === '=' || $assoc[$last] === '@') { $leaf = $assoc[$last]; @@ -418,7 +418,13 @@ class DibiResult extends /*Nette::*/Object implements IDataSource } if ($x === NULL) { // build leaf - if ($leaf === '=') $x = $row; else $x = (object) $row; + if ($leaf === '=') { + $x = $row; + } elseif ($leaf === TRUE || $leaf === '@') { + $x = (object) $row; + } else { + $x = new $leaf($row); + } } } while ($row = $this->fetch(FALSE)); @@ -588,9 +594,10 @@ class DibiResult extends /*Nette::*/Object implements IDataSource */ final public function dump() { - $none = TRUE; - foreach ($this as $i => $row) { - if ($none) { + $i = 0; + $this->seek(0); + while ($row = $this->fetch(FALSE)) { + if ($i === 0) { echo "\n\n\n\t\n\t\t\n"; foreach ($row as $col => $foo) { @@ -598,7 +605,6 @@ class DibiResult extends /*Nette::*/Object implements IDataSource } echo "\t\n\n\n"; - $none = FALSE; } echo "\t\n\t\t\n"; @@ -607,9 +613,10 @@ class DibiResult extends /*Nette::*/Object implements IDataSource echo "\t\t\n"; } echo "\t\n"; + $i++; } - if ($none) { + if ($i === 0) { echo '

empty result set

'; } else { echo "\n
#row
", $i, "", htmlSpecialChars($col), "
\n";