Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 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
 
12
namespace Symfony\Component\HttpFoundation\Session\Flash;
13
 
14
/**
15
 * FlashBag flash message container.
16
 *
17
 * @author Drak <drak@zikula.org>
18
 */
19
class FlashBag implements FlashBagInterface
20
{
21
    private $name = 'flashes';
22
    private $flashes = [];
23
    private $storageKey;
24
 
25
    /**
26
     * @param string $storageKey The key used to store flashes in the session
27
     */
28
    public function __construct(string $storageKey = '_symfony_flashes')
29
    {
30
        $this->storageKey = $storageKey;
31
    }
32
 
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getName()
37
    {
38
        return $this->name;
39
    }
40
 
41
    public function setName(string $name)
42
    {
43
        $this->name = $name;
44
    }
45
 
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function initialize(array &$flashes)
50
    {
51
        $this->flashes = &$flashes;
52
    }
53
 
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function add(string $type, $message)
58
    {
59
        $this->flashes[$type][] = $message;
60
    }
61
 
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function peek(string $type, array $default = [])
66
    {
67
        return $this->has($type) ? $this->flashes[$type] : $default;
68
    }
69
 
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function peekAll()
74
    {
75
        return $this->flashes;
76
    }
77
 
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function get(string $type, array $default = [])
82
    {
83
        if (!$this->has($type)) {
84
            return $default;
85
        }
86
 
87
        $return = $this->flashes[$type];
88
 
89
        unset($this->flashes[$type]);
90
 
91
        return $return;
92
    }
93
 
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function all()
98
    {
99
        $return = $this->peekAll();
100
        $this->flashes = [];
101
 
102
        return $return;
103
    }
104
 
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function set(string $type, $messages)
109
    {
110
        $this->flashes[$type] = (array) $messages;
111
    }
112
 
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function setAll(array $messages)
117
    {
118
        $this->flashes = $messages;
119
    }
120
 
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function has(string $type)
125
    {
126
        return \array_key_exists($type, $this->flashes) && $this->flashes[$type];
127
    }
128
 
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function keys()
133
    {
134
        return array_keys($this->flashes);
135
    }
136
 
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function getStorageKey()
141
    {
142
        return $this->storageKey;
143
    }
144
 
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function clear()
149
    {
150
        return $this->all();
151
    }
152
}