1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\Database;
9:
10: use Nette;
11:
12:
13: /**
14: * Represents a single table row.
15: */
16: class Row extends Nette\Utils\ArrayHash implements IRow
17: {
18:
19: public function __get($key)
20: {
21: $hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys((array) $this), $key);
22: throw new Nette\MemberAccessException("Cannot read an undeclared column '$key'" . ($hint ? ", did you mean '$hint'?" : '.'));
23: }
24:
25:
26: /**
27: * Returns a item.
28: * @param mixed key or index
29: * @return mixed
30: */
31: public function offsetGet($key)
32: {
33: if (is_int($key)) {
34: $arr = array_slice((array) $this, $key, 1);
35: if (!$arr) {
36: throw new Nette\MemberAccessException("Cannot read an undeclared column '$key'.");
37: }
38: return current($arr);
39: }
40: return $this->$key;
41: }
42:
43:
44: /**
45: * Checks if $key exists.
46: * @param mixed key or index
47: * @return bool
48: */
49: public function offsetExists($key)
50: {
51: if (is_int($key)) {
52: return (bool) current(array_slice((array) $this, $key, 1));
53: }
54: return parent::offsetExists($key);
55: }
56:
57: }
58: