give
/
vendor
/
vendor-prefixed
/
symfony
/
http-foundation
/
Session
/
Attribute
/
AttributeBag.php
AttributeBag.php
2 years ago
AttributeBagInterface.php
2 years ago
NamespacedAttributeBag.php
2 years ago
AttributeBag.php
152 lines
| 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 | * Modified by impress-org on 23-January-2024 using Strauss. |
| 12 | * @see https://github.com/BrianHenryIE/strauss |
| 13 | */ |
| 14 | |
| 15 | namespace Give\Vendors\Symfony\Component\HttpFoundation\Session\Attribute; |
| 16 | |
| 17 | /** |
| 18 | * This class relates to session attribute storage. |
| 19 | */ |
| 20 | class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Countable |
| 21 | { |
| 22 | private $name = 'attributes'; |
| 23 | private $storageKey; |
| 24 | |
| 25 | protected $attributes = []; |
| 26 | |
| 27 | /** |
| 28 | * @param string $storageKey The key used to store attributes in the session |
| 29 | */ |
| 30 | public function __construct($storageKey = '_sf2_attributes') |
| 31 | { |
| 32 | $this->storageKey = $storageKey; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * {@inheritdoc} |
| 37 | */ |
| 38 | public function getName() |
| 39 | { |
| 40 | return $this->name; |
| 41 | } |
| 42 | |
| 43 | public function setName($name) |
| 44 | { |
| 45 | $this->name = $name; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * {@inheritdoc} |
| 50 | */ |
| 51 | public function initialize(array &$attributes) |
| 52 | { |
| 53 | $this->attributes = &$attributes; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * {@inheritdoc} |
| 58 | */ |
| 59 | public function getStorageKey() |
| 60 | { |
| 61 | return $this->storageKey; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * {@inheritdoc} |
| 66 | */ |
| 67 | public function has($name) |
| 68 | { |
| 69 | return \array_key_exists($name, $this->attributes); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * {@inheritdoc} |
| 74 | */ |
| 75 | public function get($name, $default = null) |
| 76 | { |
| 77 | return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * {@inheritdoc} |
| 82 | */ |
| 83 | public function set($name, $value) |
| 84 | { |
| 85 | $this->attributes[$name] = $value; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * {@inheritdoc} |
| 90 | */ |
| 91 | public function all() |
| 92 | { |
| 93 | return $this->attributes; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * {@inheritdoc} |
| 98 | */ |
| 99 | public function replace(array $attributes) |
| 100 | { |
| 101 | $this->attributes = []; |
| 102 | foreach ($attributes as $key => $value) { |
| 103 | $this->set($key, $value); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * {@inheritdoc} |
| 109 | */ |
| 110 | public function remove($name) |
| 111 | { |
| 112 | $retval = null; |
| 113 | if (\array_key_exists($name, $this->attributes)) { |
| 114 | $retval = $this->attributes[$name]; |
| 115 | unset($this->attributes[$name]); |
| 116 | } |
| 117 | |
| 118 | return $retval; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * {@inheritdoc} |
| 123 | */ |
| 124 | public function clear() |
| 125 | { |
| 126 | $return = $this->attributes; |
| 127 | $this->attributes = []; |
| 128 | |
| 129 | return $return; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Returns an iterator for attributes. |
| 134 | * |
| 135 | * @return \ArrayIterator An \ArrayIterator instance |
| 136 | */ |
| 137 | public function getIterator() |
| 138 | { |
| 139 | return new \ArrayIterator($this->attributes); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Returns the number of attributes. |
| 144 | * |
| 145 | * @return int The number of attributes |
| 146 | */ |
| 147 | public function count() |
| 148 | { |
| 149 | return \count($this->attributes); |
| 150 | } |
| 151 | } |
| 152 |