ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Flash.php
Go to the documentation of this file.
1<?php
57class Slim_Session_Flash implements ArrayAccess {
58
62 protected $sessionKey = 'flash';
63
67 protected $messages = array(
68 'prev' => array(), //flash messages from prev request
69 'next' => array(), //flash messages for next request
70 'now' => array() //flash messages for current request
71 );
72
82 public function __construct( $sessionKey = null ) {
83 if ( !is_null($sessionKey) ) {
85 }
86 $this->load();
87 }
88
95 public function setSessionKey( $key ) {
96 if ( is_null($key) ) {
97 throw new RuntimeException('Session key cannot be null');
98 }
99 $this->sessionKey = (string)$key;
100 return $this;
101 }
102
107 public function getSessionKey() {
108 return $this->sessionKey;
109 }
110
117 public function now( $key, $value ) {
118 $this->messages['now'][(string)$key] = $value;
119 return $this->save();
120 }
121
128 public function set( $key, $value ) {
129 $this->messages['next'][(string)$key] = $value;
130 return $this->save();
131 }
132
137 public function getMessages() {
138 return array_merge($this->messages['prev'], $this->messages['now']);
139 }
140
145 public function load() {
146 $this->messages['prev'] = isset($_SESSION[$this->sessionKey]) ? $_SESSION[$this->sessionKey] : array();
147 return $this;
148 }
149
155 public function keep() {
156 foreach ( $this->messages['prev'] as $key => $val ) {
157 $this->messages['next'][$key] = $val;
158 }
159 return $this->save();
160 }
161
166 public function save() {
167 $_SESSION[$this->sessionKey] = $this->messages['next'];
168 return $this;
169 }
170
171 /***** ARRAY ACCESS INTERFACE *****/
172
173 public function offsetExists( $offset ) {
174 $messages = $this->getMessages();
175 return isset($messages[$offset]);
176 }
177
178 public function offsetGet( $offset ) {
179 $messages = $this->getMessages();
180 return isset($messages[$offset]) ? $messages[$offset] : null;
181 }
182
183 public function offsetSet( $offset, $value ) {
184 $this->now($offset, $value);
185 }
186
187 public function offsetUnset( $offset ) {
188 unset($this->messages['prev'][$offset]);
189 unset($this->messages['now'][$offset]);
190 }
191
192}
$_SESSION["AccountId"]
offsetExists( $offset)
Definition: Flash.php:173
offsetUnset( $offset)
Definition: Flash.php:187
__construct( $sessionKey=null)
Constructor.
Definition: Flash.php:82
setSessionKey( $key)
Set the $_SESSION key used to access Flash messages.
Definition: Flash.php:95
offsetSet( $offset, $value)
Definition: Flash.php:183
offsetGet( $offset)
Definition: Flash.php:178
getMessages()
Get Flash messages intended for the current request's View.
Definition: Flash.php:137
load()
Load Flash messages from $_SESSION.
Definition: Flash.php:145
keep()
Transfer Flash messages from the previous request so they are available to the next request.
Definition: Flash.php:155
now( $key, $value)
Set a Flash message for the current request.
Definition: Flash.php:117
save()
Save Flash messages to $_SESSION.
Definition: Flash.php:166
getSessionKey()
Get the $_SESSION key used to access Flash messages.
Definition: Flash.php:107