Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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 string $name = 'flashes';
22
    private array $flashes = [];
23
    private string $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
    public function getName(): string
34
    {
35
        return $this->name;
36
    }
37
 
38
    public function setName(string $name)
39
    {
40
        $this->name = $name;
41
    }
42
 
43
    public function initialize(array &$flashes)
44
    {
45
        $this->flashes = &$flashes;
46
    }
47
 
48
    public function add(string $type, mixed $message)
49
    {
50
        $this->flashes[$type][] = $message;
51
    }
52
 
53
    public function peek(string $type, array $default = []): array
54
    {
55
        return $this->has($type) ? $this->flashes[$type] : $default;
56
    }
57
 
58
    public function peekAll(): array
59
    {
60
        return $this->flashes;
61
    }
62
 
63
    public function get(string $type, array $default = []): array
64
    {
65
        if (!$this->has($type)) {
66
            return $default;
67
        }
68
 
69
        $return = $this->flashes[$type];
70
 
71
        unset($this->flashes[$type]);
72
 
73
        return $return;
74
    }
75
 
76
    public function all(): array
77
    {
78
        $return = $this->peekAll();
79
        $this->flashes = [];
80
 
81
        return $return;
82
    }
83
 
84
    public function set(string $type, string|array $messages)
85
    {
86
        $this->flashes[$type] = (array) $messages;
87
    }
88
 
89
    public function setAll(array $messages)
90
    {
91
        $this->flashes = $messages;
92
    }
93
 
94
    public function has(string $type): bool
95
    {
96
        return \array_key_exists($type, $this->flashes) && $this->flashes[$type];
97
    }
98
 
99
    public function keys(): array
100
    {
101
        return array_keys($this->flashes);
102
    }
103
 
104
    public function getStorageKey(): string
105
    {
106
        return $this->storageKey;
107
    }
108
 
109
    public function clear(): mixed
110
    {
111
        return $this->all();
112
    }
113
}