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