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

- DibiResult::fetchAssoc() respects 'resultObject' configuration option

- DibiResult::dump() forces arrays
- updated Nette::Object
This commit is contained in:
David Grudl
2008-09-03 22:47:49 +00:00
parent d4f9e0378f
commit 52d2ecf5b0
2 changed files with 28 additions and 13 deletions

View File

@@ -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

View File

@@ -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<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n";
foreach ($row as $col => $foo) {
@@ -598,7 +605,6 @@ class DibiResult extends /*Nette::*/Object implements IDataSource
}
echo "\t</tr>\n</thead>\n<tbody>\n";
$none = FALSE;
}
echo "\t<tr>\n\t\t<th>", $i, "</th>\n";
@@ -607,9 +613,10 @@ class DibiResult extends /*Nette::*/Object implements IDataSource
echo "\t\t<td>", htmlSpecialChars($col), "</td>\n";
}
echo "\t</tr>\n";
$i++;
}
if ($none) {
if ($i === 0) {
echo '<p><em>empty result set</em></p>';
} else {
echo "</tbody>\n</table>\n";