-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConfig.php
More file actions
224 lines (195 loc) · 5.11 KB
/
Copy pathConfig.php
File metadata and controls
224 lines (195 loc) · 5.11 KB
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
<?php
namespace Foolz\Cache;
class Config
{
/**
* The storage engine being used
*
* @var null|string
*/
protected $storage = null;
/**
* The format object relative to the format selected
*
* @var \Foolz\Cache\Format
*/
protected $format = null;
/**
* A prefix for the keys so they don't get mixed with variables from other storages
*
* @var string
*/
protected $prefix = '';
/**
* If true, rather than returning Void, an exception will be thrown
*
* @var boolean
*/
protected $throw = false;
/**
* Returns an instance for the storage selected
*
* @param string $storage The name of the storage
*
* @return \Foolz\Cache\Config The Config class specific to the storage
* @throws \DomainException If the storage engine selected doesn't exist
*/
public static function forge($storage)
{
$class = '\Foolz\Cache\Config\\'.Util::lowercaseToClassName($storage);
// check that we have such a storage engine
if (!class_exists($class)) {
throw new \DomainException('The storage engine selected doesn\'t exist.');
}
return new $class();
}
/**
* Shorthand that allows using IDE suggestions
*
* @return \Foolz\Cache\Config\Apc
*/
public static function forgeApc()
{
return static::forge('apc');
}
/**
* Shorthand that allows using IDE suggestions
*
* @return \Foolz\Cache\Config\Memcached
*/
public static function forgeMemcached()
{
return static::forge('memcached');
}
/**
* Shorthand that allows using IDE suggestions
*
* @return \Foolz\Cache\Config\Redis
*/
public static function forgeRedis()
{
return static::forge('redis');
}
/**
* Shorthand that allows using IDE suggestions
*
* @return \Foolz\Cache\Config\Db
*/
public static function forgeDb()
{
return static::forge('db');
}
/**
* Shorthand that allows using IDE suggestions
*
* @return \Foolz\Cache\Config\File
*/
public static function forgeFile()
{
return static::forge('file');
}
/**
* Shorthand that allows using IDE suggestions
*
* @return \Foolz\Cache\Config\File
*/
public static function forgeDummy()
{
return static::forge('dummy');
}
/**
* Shorthand that allows using IDE suggestions
*
* @return \Foolz\Cache\Config\File
*/
public static function forgeVolatile()
{
return static::forge('volatile');
}
/**
* Get the selected storage engine
*
* @return string The name of the storage engine
* @throws \BadMethodCallException If the storage engine hasn't been set yet
*/
public function getStorage()
{
if ($this->storage === null) {
throw new \BadMethodCallException('The storage engine was not set.');
}
return $this->storage;
}
/**
* Sets the format to use
*
* @param string $format The name of the format
*
* @throws \DomainException In case the format doesn't exist
*/
public function setFormat($format)
{
$class = '\Foolz\Cache\Format\\'.Util::lowercaseToClassName($format);
// check that we have such a storage engine
if (!class_exists($class)) {
throw new \DomainException('The format selected doesn\'t exist.');
}
$this->format = new $class();
return $this;
}
/**
* Returns the format
*
* @return \Foolz\Cache\Format The format object
*
* @throws \BadMethodCallException If the format wasn't selected
*/
public function getFormat()
{
if ($this->format === null) {
throw new \BadMethodCallException('The format wasn\'t selected.');
}
return $this->format;
}
/**
* Set a prefix for the keys
*
* @param string $prefix
*
* @return \Foolz\Cache\Config The current object
*/
public function setPrefix($prefix)
{
$this->prefix = $prefix;
return $this;
}
/**
* Returns the set prefix
*
* @return string The prefix
*/
public function getPrefix()
{
return $this->prefix;
}
/**
* Enables exceptions when the value of a key can't be found
*
* @param boolean $bool True if it should throw exceptions if the value of a key can't be found, false if it should return Void without throwing exceptions
*
* @return \Foolz\Cache\Config The current object
*/
public function setThrow($bool = false)
{
$this->throw = $bool;
return $this;
}
/**
* Returns the throw configuration
*
* @return boolean True if it should throw exceptions if the value of a key can't be found, false if it should return Void without throwing exceptions
*/
public function getThrow()
{
return $this->throw;
}
}