-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathSessionFlash.cfc
87 lines (77 loc) · 2.19 KB
/
SessionFlash.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* This flash scope is smart enough to not create unnecessary session variables
* unless data is put in it. Else, it does not abuse session.
*
* @author Luis Majano <lmajano@ortussolutions.com>
*/
component extends="coldbox.system.web.flash.AbstractFlashScope" accessors="true" {
// The flash key
property name="flashKey";
/**
* Constructor
*
* @controller.hint ColdBox Controller
* @defaults.hint Default flash data packet for the flash RAM object=[scope,properties,inflateToRC,inflateToPRC,autoPurge,autoSave]
*/
function init( required controller, required struct defaults = {} ){
super.init( argumentCollection = arguments );
variables.flashKey = "cbox_flash_scope";
return this;
}
/**
* Save the flash storage in preparing to go to the next request
*
* @return SessionFlash
*/
function saveFlash(){
lock scope="session" type="exclusive" throwontimeout="true" timeout="20" {
session[ variables.flashKey ] = getScope();
}
return this;
}
/**
* Checks if the flash storage exists and IT HAS DATA to inflate.
*/
boolean function flashExists(){
// Check if session is defined first
if ( NOT getApplicationMetadata().sessionManagement ) {
return false;
}
// Check if storage is set and not empty, try/catch due to ACF11 bug, trying it out.
try {
return ( structKeyExists( session, getFlashKey() ) AND NOT structIsEmpty( session[ getFlashKey() ] ) );
} catch ( any e ) {
writeLog(
text = "Error checking flash exists: #e.message# #e.detail#",
type = "error",
file = "coldbox.SessionFlash"
);
return false;
}
}
/**
* Get the flash storage structure to inflate it.
*/
struct function getFlash(){
if ( flashExists() ) {
lock scope="session" type="readonly" throwontimeout="true" timeout="20" {
return session[ variables.flashKey ];
}
}
return {};
}
/**
* Remove the entire flash storage
*
* @return SessionFlash
*/
function removeFlash(){
lock scope="session" type="exclusive" throwontimeout="true" timeout="20" {
structDelete( session, getFlashKey() );
}
return this;
}
}