Open Monograph Press  3.3.0
lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.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 
20 {
21  private $name = 'flashes';
22 
28  private $flashes = array('display' => array(), 'new' => 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  // The logic: messages from the last request will be stored in new, so we move them to previous
68  // This request we will show what is in 'display'. What is placed into 'new' this time round will
69  // be moved to display next time round.
70  $this->flashes['display'] = array_key_exists('new', $this->flashes) ? $this->flashes['new'] : array();
71  $this->flashes['new'] = array();
72  }
73 
77  public function add($type, $message)
78  {
79  $this->flashes['new'][$type][] = $message;
80  }
81 
85  public function peek($type, array $default = array())
86  {
87  return $this->has($type) ? $this->flashes['display'][$type] : $default;
88  }
89 
93  public function peekAll()
94  {
95  return array_key_exists('display', $this->flashes) ? (array) $this->flashes['display'] : array();
96  }
97 
101  public function get($type, array $default = array())
102  {
103  $return = $default;
104 
105  if (!$this->has($type)) {
106  return $return;
107  }
108 
109  if (isset($this->flashes['display'][$type])) {
110  $return = $this->flashes['display'][$type];
111  unset($this->flashes['display'][$type]);
112  }
113 
114  return $return;
115  }
116 
120  public function all()
121  {
122  $return = $this->flashes['display'];
123  $this->flashes = array('new' => array(), 'display' => array());
124 
125  return $return;
126  }
127 
131  public function setAll(array $messages)
132  {
133  $this->flashes['new'] = $messages;
134  }
135 
139  public function set($type, $messages)
140  {
141  $this->flashes['new'][$type] = (array) $messages;
142  }
143 
147  public function has($type)
148  {
149  return array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type];
150  }
151 
155  public function keys()
156  {
157  return array_keys($this->flashes['display']);
158  }
159 
163  public function getStorageKey()
164  {
165  return $this->storageKey;
166  }
167 
171  public function clear()
172  {
173  return $this->all();
174  }
175 }
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\has
has($type)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:153
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\getStorageKey
getStorageKey()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:169
Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
Definition: lib/vendor/symfony/http-foundation/Session/Flash/FlashBagInterface.php:21
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\getName
getName()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:56
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\setAll
setAll(array $messages)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:137
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\setName
setName($name)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:61
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\all
all()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:126
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\peekAll
peekAll()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:99
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\__construct
__construct($storageKey='_sf2_flashes')
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:48
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\keys
keys()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:161
Symfony\Component\HttpFoundation\Session\Flash
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:12
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\initialize
initialize(array &$flashes)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:69
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\peek
peek($type, array $default=array())
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:91
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\add
add($type, $message)
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:83
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:19
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\clear
clear()
Definition: lib/vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:177