PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.0
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / libs / Zend / Registry.php
matomo / app / libs / Zend Last commit date
Db 5 years ago Session 5 years ago Config.php 6 years ago Db.php 6 years ago Exception.php 6 years ago LICENSE.txt 6 years ago Registry.php 6 years ago Session.php 5 years ago Version.php 6 years ago
Registry.php
211 lines
1 <?php
2 /**
3 * Zend Framework
4 *
5 * LICENSE
6 *
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category Zend
16 * @package Zend_Registry
17 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Registry.php 23775 2011-03-01 17:25:24Z ralph $
20 */
21
22 /**
23 * Generic storage class helps to manage global data.
24 *
25 * @category Zend
26 * @package Zend_Registry
27 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
28 * @license http://framework.zend.com/license/new-bsd New BSD License
29 */
30 class Zend_Registry extends ArrayObject
31 {
32 /**
33 * Class name of the singleton registry object.
34 * @var string
35 */
36 private static $_registryClassName = 'Zend_Registry';
37
38 /**
39 * Registry object provides storage for shared objects.
40 * @var Zend_Registry
41 */
42 private static $_registry = null;
43
44 /**
45 * Retrieves the default registry instance.
46 *
47 * @return Zend_Registry
48 */
49 public static function getInstance()
50 {
51 if (self::$_registry === null) {
52 self::init();
53 }
54
55 return self::$_registry;
56 }
57
58 /**
59 * Set the default registry instance to a specified instance.
60 *
61 * @param Zend_Registry $registry An object instance of type Zend_Registry,
62 * or a subclass.
63 * @return void
64 * @throws Zend_Exception if registry is already initialized.
65 */
66 public static function setInstance(Zend_Registry $registry)
67 {
68 if (self::$_registry !== null) {
69 // require_once 'Zend/Exception.php';
70 throw new Zend_Exception('Registry is already initialized');
71 }
72
73 self::setClassName(get_class($registry));
74 self::$_registry = $registry;
75 }
76
77 /**
78 * Initialize the default registry instance.
79 *
80 * @return void
81 */
82 protected static function init()
83 {
84 self::setInstance(new self::$_registryClassName());
85 }
86
87 /**
88 * Set the class name to use for the default registry instance.
89 * Does not affect the currently initialized instance, it only applies
90 * for the next time you instantiate.
91 *
92 * @param string $registryClassName
93 * @return void
94 * @throws Zend_Exception if the registry is initialized or if the
95 * class name is not valid.
96 */
97 public static function setClassName($registryClassName = 'Zend_Registry')
98 {
99 if (self::$_registry !== null) {
100 // require_once 'Zend/Exception.php';
101 throw new Zend_Exception('Registry is already initialized');
102 }
103
104 if (!is_string($registryClassName)) {
105 // require_once 'Zend/Exception.php';
106 throw new Zend_Exception("Argument is not a class name");
107 }
108
109 /**
110 * @see Zend_Loader
111 */
112 if (!class_exists($registryClassName)) {
113 // require_once 'Zend/Loader.php';
114 Zend_Loader::loadClass($registryClassName);
115 }
116
117 self::$_registryClassName = $registryClassName;
118 }
119
120 /**
121 * Unset the default registry instance.
122 * Primarily used in tearDown() in unit tests.
123 * @returns void
124 */
125 public static function _unsetInstance()
126 {
127 self::$_registry = null;
128 }
129
130 /**
131 * getter method, basically same as offsetGet().
132 *
133 * This method can be called from an object of type Zend_Registry, or it
134 * can be called statically. In the latter case, it uses the default
135 * static instance stored in the class.
136 *
137 * @param string $index - get the value associated with $index
138 * @return mixed
139 * @throws Zend_Exception if no entry is registerd for $index.
140 */
141 public static function get($index)
142 {
143 $instance = self::getInstance();
144
145 if (!$instance->offsetExists($index)) {
146 // require_once 'Zend/Exception.php';
147 // debug_print_backtrace();
148 throw new Zend_Exception("No entry is registered for key '$index'" );
149 }
150
151 return $instance->offsetGet($index);
152 }
153
154 /**
155 * setter method, basically same as offsetSet().
156 *
157 * This method can be called from an object of type Zend_Registry, or it
158 * can be called statically. In the latter case, it uses the default
159 * static instance stored in the class.
160 *
161 * @param string $index The location in the ArrayObject in which to store
162 * the value.
163 * @param mixed $value The object to store in the ArrayObject.
164 * @return void
165 */
166 public static function set($index, $value)
167 {
168 $instance = self::getInstance();
169 $instance->offsetSet($index, $value);
170 }
171
172 /**
173 * Returns TRUE if the $index is a named value in the registry,
174 * or FALSE if $index was not found in the registry.
175 *
176 * @param string $index
177 * @return boolean
178 */
179 public static function isRegistered($index)
180 {
181 if (self::$_registry === null) {
182 return false;
183 }
184 return self::$_registry->offsetExists($index);
185 }
186
187 /**
188 * Constructs a parent ArrayObject with default
189 * ARRAY_AS_PROPS to allow acces as an object
190 *
191 * @param array $array data array
192 * @param integer $flags ArrayObject flags
193 */
194 public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS)
195 {
196 parent::__construct($array, $flags);
197 }
198
199 /**
200 * @param string $index
201 * @returns mixed
202 *
203 * Workaround for http://bugs.php.net/bug.php?id=40442 (ZF-960).
204 */
205 public function offsetExists($index)
206 {
207 return array_key_exists($index, $this);
208 }
209
210 }
211