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\Attribute;
13
 
14
/**
15
 * This class relates to session attribute storage.
16
 *
17
 * @implements \IteratorAggregate<string, mixed>
18
 */
19
class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Countable
20
{
21
    private string $name = 'attributes';
22
    private string $storageKey;
23
 
24
    protected $attributes = [];
25
 
26
    /**
27
     * @param string $storageKey The key used to store attributes in the session
28
     */
29
    public function __construct(string $storageKey = '_sf2_attributes')
30
    {
31
        $this->storageKey = $storageKey;
32
    }
33
 
34
    public function getName(): string
35
    {
36
        return $this->name;
37
    }
38
 
39
    public function setName(string $name)
40
    {
41
        $this->name = $name;
42
    }
43
 
44
    public function initialize(array &$attributes)
45
    {
46
        $this->attributes = &$attributes;
47
    }
48
 
49
    public function getStorageKey(): string
50
    {
51
        return $this->storageKey;
52
    }
53
 
54
    public function has(string $name): bool
55
    {
56
        return \array_key_exists($name, $this->attributes);
57
    }
58
 
59
    public function get(string $name, mixed $default = null): mixed
60
    {
61
        return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
62
    }
63
 
64
    public function set(string $name, mixed $value)
65
    {
66
        $this->attributes[$name] = $value;
67
    }
68
 
69
    public function all(): array
70
    {
71
        return $this->attributes;
72
    }
73
 
74
    public function replace(array $attributes)
75
    {
76
        $this->attributes = [];
77
        foreach ($attributes as $key => $value) {
78
            $this->set($key, $value);
79
        }
80
    }
81
 
82
    public function remove(string $name): mixed
83
    {
84
        $retval = null;
85
        if (\array_key_exists($name, $this->attributes)) {
86
            $retval = $this->attributes[$name];
87
            unset($this->attributes[$name]);
88
        }
89
 
90
        return $retval;
91
    }
92
 
93
    public function clear(): mixed
94
    {
95
        $return = $this->attributes;
96
        $this->attributes = [];
97
 
98
        return $return;
99
    }
100
 
101
    /**
102
     * Returns an iterator for attributes.
103
     *
104
     * @return \ArrayIterator<string, mixed>
105
     */
106
    public function getIterator(): \ArrayIterator
107
    {
108
        return new \ArrayIterator($this->attributes);
109
    }
110
 
111
    /**
112
     * Returns the number of attributes.
113
     */
114
    public function count(): int
115
    {
116
        return \count($this->attributes);
117
    }
118
}