1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Core;
13:
14: /**
15: * Registry - a non-persisted key value store
16: *
17: * Earlier version was based on Zend_Registry, some names preserved
18: *
19: * @category Xoops\Core\Registry
20: * @package Registry
21: * @author trabis <lusopoemas@gmail.com>
22: * @author Richard Griffith <richard@geekwright.com>
23: * @copyright 2013-2014 XOOPS Project (http://xoops.org)
24: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
25: * @link http://xoops.org
26: */
27: class Registry extends \ArrayObject implements AttributeInterface
28: {
29:
30: /**
31: * Retrieve a registry entry value.
32: *
33: * @param string $name Name of the registry entry
34: * @param mixed $default A default value returned if the requested
35: * registry entry is not set.
36: *
37: * @return mixed The value of the attribute, or null if not set.
38: */
39: public function get($name, $default = null)
40: {
41: if ($this->offsetExists($name)) {
42: return $this->offsetGet($name);
43: } else {
44: return $default;
45: }
46: }
47:
48: /**
49: * Set a registry entry value.
50: *
51: * @param string $name Name of the registry entry
52: * @param mixed $value Value for the registry entry
53: *
54: * @return void
55: */
56: public function set($name, $value)
57: {
58: $this->offsetSet($name, $value);
59: }
60:
61: /**
62: * has - test if registry entry with a given name is set
63: *
64: * @param string $name Name of the registry entry
65: *
66: * @return boolean true if name is registered
67: */
68: public function has($name)
69: {
70: return $this->offsetExists($name);
71: }
72:
73: /**
74: * Remove an attribute.
75: *
76: * @param string $name An attribute name.
77: *
78: * @return mixed An attribute value, if the named attribute existed and
79: * has been removed, otherwise NULL.
80: */
81: public function remove($name)
82: {
83: $value = null;
84: if ($this->offsetExists($name)) {
85: $value = $this->offsetGet($name);
86: $this->offsetUnset($name);
87: }
88:
89: return $value;
90: }
91:
92: /**
93: * Remove all attributes.
94: *
95: * @return array old values
96: */
97: public function clear()
98: {
99: return $this->exchangeArray(array());
100: }
101: }
102: