Open Monograph Press  3.3.0
lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
19 class FlashBag implements FlashBagInterface
20 {
21  private $name = 'flashes';
22 
28  private $flashes = array();
29 
35  private $storageKey;
36 
42  public function __construct($storageKey = '_sf2_flashes')
43  {
44  $this->storageKey = $storageKey;
45  }
46 
50  public function getName()
51  {
52  return $this->name;
53  }
54 
55  public function setName($name)
56  {
57  $this->name = $name;
58  }
59 
63  public function initialize(array &$flashes)
64  {
65  $this->flashes = &$flashes;
66  }
67 
71  public function add($type, $message)
72  {
73  $this->flashes[$type][] = $message;
74  }
75 
79  public function peek($type, array $default = array())
80  {
81  return $this->has($type) ? $this->flashes[$type] : $default;
82  }
83 
87  public function peekAll()
88  {
89  return $this->flashes;
90  }
91 
95  public function get($type, array $default = array())
96  {
97  if (!$this->has($type)) {
98  return $default;
99  }
100 
101  $return = $this->flashes[$type];
102 
103  unset($this->flashes[$type]);
104 
105  return $return;
106  }
107 
111  public function all()
112  {
113  $return = $this->peekAll();
114  $this->flashes = array();
115 
116  return $return;
117  }
118 
122  public function set($type, $messages)
123  {
124  $this->flashes[$type] = (array) $messages;
125  }
126 
130  public function setAll(array $messages)
131  {
132  $this->flashes = $messages;
133  }
134 
138  public function has($type)
139  {
140  return array_key_exists($type, $this->flashes) && $this->flashes[$type];
141  }
142 
146  public function keys()
147  {
148  return array_keys($this->flashes);
149  }
150 
154  public function getStorageKey()
155  {
156  return $this->storageKey;
157  }
158 
162  public function clear()
163  {
164  return $this->all();
165  }
166 }
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\__construct
__construct($storageKey='_sf2_flashes')
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:48
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\getStorageKey
getStorageKey()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:160
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\has
has($type)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:144
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\keys
keys()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:152
Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBagInterface.php:21
Symfony\Component\HttpFoundation\Session\Flash\FlashBag
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:19
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\clear
clear()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:168
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\setName
setName($name)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:61
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\peek
peek($type, array $default=array())
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:85
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\getName
getName()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:56
Symfony\Component\HttpFoundation\Session\Flash
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:12
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\setAll
setAll(array $messages)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:136
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\all
all()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:117
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\add
add($type, $message)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:77
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\peekAll
peekAll()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:93
Symfony\Component\HttpFoundation\Session\Flash\FlashBag\initialize
initialize(array &$flashes)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBag.php:69