1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: * @package Nette\Database
11: */
12:
13:
14:
15: /**
16: * Represents a single table row.
17: *
18: * @author David Grudl
19: * @package Nette\Database
20: */
21: class Row extends ArrayHash
22: {
23:
24: public function __construct(Statement $statement)
25: {
26: $data = array();
27: foreach ($this as $key => $value) {
28: $data[$key] = $value;
29: unset($this->$key);
30: }
31: foreach ($statement->normalizeRow($data) as $key => $value) {
32: $this->$key = $value;
33: }
34: }
35:
36:
37: /**
38: * Returns a item.
39: * @param mixed key or index
40: * @return mixed
41: */
42: public function offsetGet($key)
43: {
44: if (is_int($key)) {
45: $arr = array_slice((array) $this, $key, 1);
46: if (!$arr) {
47: trigger_error('Undefined offset: ' . __CLASS__ . "[$key]", E_USER_NOTICE);
48: }
49: return current($arr);
50: }
51: return $this->$key;
52: }
53:
54:
55: public function offsetExists($key)
56: {
57: if (is_int($key)) {
58: return (bool) array_slice((array) $this, $key, 1);
59: }
60: return parent::offsetExists($key);
61: }
62:
63: }
64: