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: * @author Jan Skrasek
18: */
19: class Row extends Nette\Utils\ArrayHash implements IRow
20: {
21:
22: public function __get($key)
23: {
24: throw new Nette\MemberAccessException("Cannot read an undeclared column '$key'.");
25: }
26:
27:
28: /**
29: * Returns a item.
30: * @param mixed key or index
31: * @return mixed
32: */
33: public function offsetGet($key)
34: {
35: if (is_int($key)) {
36: $arr = array_slice((array) $this, $key, 1);
37: if (!$arr) {
38: throw new Nette\MemberAccessException("Cannot read an undeclared column '$key'.");
39: }
40: return current($arr);
41: }
42: return $this->$key;
43: }
44:
45:
46: /**
47: * Checks if $key exists.
48: * @param mixed key or index
49: * @return bool
50: */
51: public function offsetExists($key)
52: {
53: if (is_int($key)) {
54: return (bool) current(array_slice((array) $this, $key, 1));
55: }
56: return parent::offsetExists($key);
57: }
58:
59: }
60: