|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Message |
|
5
|
|
|
* |
|
6
|
|
|
* Pass cross-requests messages. |
|
7
|
|
|
* |
|
8
|
|
|
* @package core |
|
9
|
|
|
* @author [email protected] |
|
10
|
|
|
* @copyright Caffeina srl - 2015 - http://caffeina.it |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
class Message extends Dictionary { |
|
14
|
|
|
|
|
15
|
|
|
protected static $loaded = false; |
|
16
|
|
|
protected static $fields = []; |
|
17
|
|
|
|
|
18
|
|
|
protected static function init(){ |
|
19
|
|
|
if(false===static::$loaded){ |
|
20
|
|
|
static::load(Session::get('core.messages',[])); |
|
21
|
|
|
static::$loaded = true; |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public static function & get($key,$default=null){ |
|
26
|
|
|
static::init(); |
|
27
|
|
|
$value = parent::get($key,''); |
|
28
|
|
|
parent::delete($key,''); |
|
29
|
|
|
Session::set('core.messages',parent::all()); |
|
30
|
|
|
return $value; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public static function set($key,$data=null){ |
|
34
|
|
|
static::init(); |
|
35
|
|
|
parent::set($key,$data); |
|
36
|
|
|
return Session::set('core.messages',parent::all()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public static function add($key,$data=null){ |
|
40
|
|
|
static::init(); |
|
41
|
|
|
$d = parent::get($key,[]); |
|
42
|
|
|
$d[] = $data; |
|
43
|
|
|
parent::set($key,$d); |
|
44
|
|
|
return Session::set('core.messages',parent::all()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function & all($key=null){ |
|
48
|
|
|
static::init(); |
|
49
|
|
|
if($key){ |
|
50
|
|
|
$all = parent::get($key,[]); |
|
51
|
|
|
parent::delete($key); |
|
52
|
|
|
Session::set('core.messages',parent::all()); |
|
53
|
|
|
} else { |
|
54
|
|
|
$all = parent::all(); |
|
55
|
|
|
static::clear(); |
|
56
|
|
|
} |
|
57
|
|
|
return $all; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public static function clear(){ |
|
61
|
|
|
static::init(); |
|
62
|
|
|
parent::clear(); |
|
63
|
|
|
Session::delete('core.messages'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Return a read-only accessor to messages variables for in-view use. |
|
69
|
|
|
* @return MessageReadOnly |
|
70
|
|
|
*/ |
|
71
|
|
|
public static function readOnly(){ |
|
72
|
|
|
return new MessageReadOnly(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
} /* End of class */ |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Read-only Message accessor class |
|
80
|
|
|
*/ |
|
81
|
|
|
|
|
82
|
|
|
class MessageReadOnly { |
|
83
|
|
|
|
|
84
|
|
|
public function __get($key){ |
|
85
|
|
|
return Message::get($key); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function __isset($key){ |
|
89
|
|
|
return true; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} /* End of class */ |
|
93
|
|
|
|