Ubiquity  2.0.0
php rapid development framework
FlashBag.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
12 class FlashBag implements \Iterator {
13  const FLASH_BAG_KEY="_flash_bag";
14  private $array;
15  private $position;
16 
17  public function __construct() {
19  $this->array=USession::get(self::FLASH_BAG_KEY, [ ]);
20  }
21 
22  public function addMessage($type, $content, $icon=NULL) {
23  $this->array[]=new FlashMessage($type, $content, $icon);
24  }
25 
26  public function getMessages($type) {
27  $result=[ ];
28  foreach ( $this->array as $msg ) {
29  if ($msg->getType() == $type)
30  $result[]=$msg;
31  }
32  return $result;
33  }
34 
35  public function getAll() {
36  return $this->array;
37  }
38 
39  public function clear() {
40  USession::delete(self::FLASH_BAG_KEY);
41  }
42 
43  public function rewind() {
44  $this->position=0;
45  }
46 
47  public function current() {
48  return $this->array[$this->position];
49  }
50 
51  public function key() {
52  return $this->position;
53  }
54 
55  public function next() {
57  }
58 
59  public function valid() {
60  return isset($this->array[$this->position]);
61  }
62 
63  public function save() {
64  $this->array=USession::set(self::FLASH_BAG_KEY, $this->array);
65  }
66 }
67 
static delete($key)
Deletes the key in Session.
Definition: USession.php:133
addMessage($type, $content, $icon=NULL)
Definition: FlashBag.php:22
static set($key, $value)
Adds or sets a value to the Session at position $key.
Definition: USession.php:124
static get($key, $default=NULL)
Returns the value stored at the key position in session.
Definition: USession.php:114
Bag for Session Flash messages.
Definition: FlashBag.php:12
static start($name=null)
Start new or resume existing session.
Definition: USession.php:162