forked from Enrise/Glitch_Lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Registry.php
234 lines (216 loc) · 5.48 KB
/
Registry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/**
* Glitch
*
* This source file is proprietary and protected by international
* copyright and trade secret laws. No part of this source file may
* be reproduced, copied, adapted, modified, distributed, transferred,
* translated, disclosed, displayed or otherwise used by anyone in any
* form or by any means without the express written authorization of
* 4worx software innovators BV (www.4worx.com)
*
* @category Glitch
* @package Glitch
* @author 4worx <[email protected]>
* @copyright 2010, 4worx
* @version $Id$
*/
/**
* Storage class for managing global data
*
* This class implements convenience methods to allow for easy, consistent access to common objects.
*
* It uses named methods (e.g. getConfig()) rather than hash look-ups (e.g. get('config')) because:
* (1) Named methods allow for additional implementation
* (2) Named methods do not depend upon a specific, hard-coded key ('config')
*
* @category Glitch
* @package Glitch
*/
class Glitch_Registry extends Zend_Registry
{
/**#@+
* Names of the registry keys
*
* @var string
*/
const KEY_CONFIG = 'config';
const KEY_SETTINGS = 'settings';
const KEY_DB = 'db';
const KEY_ENCODING = 'encoding';
const KEY_LOCALE = 'Zend_Locale'; // Special case, required by ZF
const KEY_TRANSLATE = 'Zend_Translate'; // Special case, required by ZF
const KEY_LOG = 'log';
/**#@-*/
/**
* Registry for the various registered caches on the Cache Manager
*
* @var array
*/
private static $_managedCaches = array();
/**
* Gets the configuration
*
* @return Zend_Config
*/
public static function getConfig()
{
return self::get(self::KEY_CONFIG);
}
/**
* Sets the configuration
*
* @param Zend_Config $config
* @return void
*/
public static function setConfig(Zend_Config $config)
{
self::set(self::KEY_CONFIG, $config);
}
/**
* Gets the application settings
*
* @return Zend_Config
*/
public static function getSettings()
{
return self::get(self::KEY_SETTINGS);
}
/**
* Sets the application settings
*
* @param Zend_Config $config
* @return void
*/
public static function setSettings(Zend_Config $config)
{
self::set(self::KEY_SETTINGS, $config);
}
/**
* Gets the database adapter
*
* @return Zend_Db_Adapter_Abstract
*/
public static function getDb()
{
return self::get(self::KEY_DB);
}
/**
* Sets the database adapter
*
* @param Zend_Db_Adapter_Abstract $db
* @return void
*/
public static function setDb(Zend_Db_Adapter_Abstract $db)
{
self::set(self::KEY_DB, $db);
}
/**
* Gets the encoding
*
* @return string
*/
public static function getEncoding()
{
return self::get(self::KEY_ENCODING);
}
/**
* Sets the encoding
*
* @param string $encoding
* @return void
*/
public static function setEncoding($encoding)
{
self::set(self::KEY_ENCODING, $encoding);
}
/**
* Gets the locale
*
* @return Zend_Locale
*/
public static function getLocale()
{
return self::get(self::KEY_LOCALE);
}
/**
* Sets the locale
*
* @param Zend_Locale $locale
* @return void
*/
public static function setLocale(Zend_Locale $locale)
{
self::set(self::KEY_LOCALE, $locale);
}
/**
* Gets the logger
*
* @return Zend_Log
*/
public static function getLog()
{
return self::get(self::KEY_LOG);
}
/**
* Sets the logger
*
* @param Zend_Log $log
* @return void
*/
public static function setLog(Zend_Log $log)
{
self::set(self::KEY_LOG, $log);
}
/**
* Gets the translator
*
* @return Zend_Translate
*/
public static function getTranslate()
{
return self::get(self::KEY_TRANSLATE);
}
/**
* Sets the translator
*
* @param Zend_Translate $translate
* @return void
*/
public static function setTranslate(Zend_Translate $translate)
{
self::set(self::KEY_TRANSLATE, $translate);
}
/**
* Get a cache type from the cache manager
*
* Get a cache type via the Cache Manager instance or instantiate the object if not
* exists. Attempts to load from bootstrap if available.
*
* @param string
* @return Zend_Cache_Core
* @throws InvalidArgumentException when incorrect type is provided
*/
public static function getCache($type)
{
if (is_string($type) && !array_key_exists($type, self::$_managedCaches))
{
$front = Zend_Controller_Front::getInstance();
if ($front->getParam('bootstrap') && $front->getParam('bootstrap')->getResource('CacheManager'))
{
$manager = $front->getParam('bootstrap')
->getResource('CacheManager');
}
else
{
$manager = new Zend_Cache_Manager();
}
if (!$manager->hasCache($type))
{
throw new InvalidArgumentException('Cache of type '. $type . ' does not exist!');
}
self::$_managedCaches[$type] = $manager->getCache($type);
}
return self::$_managedCaches[$type];
}
}