Open Journal Systems  3.3.0
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 
19 class AutoExpireFlashBag implements FlashBagInterface
20 {
21  private $name = 'flashes';
22  private $flashes = ['display' => [], 'new' => []];
23  private $storageKey;
24 
28  public function __construct(string $storageKey = '_symfony_flashes')
29  {
30  $this->storageKey = $storageKey;
31  }
32 
36  public function getName()
37  {
38  return $this->name;
39  }
40 
41  public function setName($name)
42  {
43  $this->name = $name;
44  }
45 
49  public function initialize(array &$flashes)
50  {
51  $this->flashes = &$flashes;
52 
53  // The logic: messages from the last request will be stored in new, so we move them to previous
54  // This request we will show what is in 'display'. What is placed into 'new' this time round will
55  // be moved to display next time round.
56  $this->flashes['display'] = \array_key_exists('new', $this->flashes) ? $this->flashes['new'] : [];
57  $this->flashes['new'] = [];
58  }
59 
63  public function add($type, $message)
64  {
65  $this->flashes['new'][$type][] = $message;
66  }
67 
71  public function peek($type, array $default = [])
72  {
73  return $this->has($type) ? $this->flashes['display'][$type] : $default;
74  }
75 
79  public function peekAll()
80  {
81  return \array_key_exists('display', $this->flashes) ? (array) $this->flashes['display'] : [];
82  }
83 
87  public function get($type, array $default = [])
88  {
89  $return = $default;
90 
91  if (!$this->has($type)) {
92  return $return;
93  }
94 
95  if (isset($this->flashes['display'][$type])) {
96  $return = $this->flashes['display'][$type];
97  unset($this->flashes['display'][$type]);
98  }
99 
100  return $return;
101  }
102 
106  public function all()
107  {
108  $return = $this->flashes['display'];
109  $this->flashes['display'] = [];
110 
111  return $return;
112  }
113 
117  public function setAll(array $messages)
118  {
119  $this->flashes['new'] = $messages;
120  }
121 
125  public function set($type, $messages)
126  {
127  $this->flashes['new'][$type] = (array) $messages;
128  }
129 
133  public function has($type)
134  {
135  return \array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type];
136  }
137 
141  public function keys()
142  {
143  return array_keys($this->flashes['display']);
144  }
145 
149  public function getStorageKey()
150  {
151  return $this->storageKey;
152  }
153 
157  public function clear()
158  {
159  return $this->all();
160  }
161 }
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: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:149
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\getName
getName()
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:36
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\setAll
setAll(array $messages)
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:117
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\setName
setName($name)
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:41
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\all
all()
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:106
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\peekAll
peekAll()
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:79
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\keys
keys()
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:141
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: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:49
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\__construct
__construct(string $storageKey='_symfony_flashes')
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:28
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\add
add($type, $message)
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:63
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\peek
peek($type, array $default=[])
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:71
Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag\clear
clear()
Definition: vendor/symfony/http-foundation/Session/Flash/AutoExpireFlashBag.php:157