-
Notifications
You must be signed in to change notification settings - Fork 3
/
ServerContainer.cfc
64 lines (48 loc) · 1.58 KB
/
ServerContainer.cfc
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
component implements = "IContainer" {
ServerContainer function init(required string name) {
variables.name = arguments.name;
// make sure the store exists within server scope
if(!structKeyExists(server, variables.name)) {
server[variables.name] = {};
}
return this;
}
void function clear() {
structClear(server[variables.name]);
}
boolean function containsKey(required string key) {
return structKeyExists(server, variables.name) && structKeyExists(server[variables.name], arguments.key);
}
void function destroy() {
structDelete(server, variables.name);
}
any function get(required string key) {
if(containsKey(arguments.key)) {
return server[variables.name][arguments.key];
}
}
boolean function isEmpty() {
return !structKeyExists(server, variables.name) || structIsEmpty(server[variables.name]);
}
string function keyList() {
if(structKeyExists(server, variables.name)) {
return listSort(structKeyList(server[variables.name]), "textnocase");
}
return "";
}
void function put(required string key, required any value) {
server[variables.name][arguments.key] = arguments.value;
}
void function putAll(required struct values, boolean clear = false, boolean overwrite = false) {
if(arguments.clear) {
this.clear();
}
structAppend(server[variables.name], arguments.values, arguments.overwrite);
}
void function remove(required string key) {
structDelete(server[variables.name], arguments.key);
}
struct function values() {
return duplicate(server[variables.name]);
}
}