| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\HttpFoundation\Session\Attribute; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Countable |
| 20 |
{ |
| 21 |
protected array $attributes = []; |
| 22 |
|
| 23 |
private string $name = 'attributes'; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function __construct( |
| 29 |
private string $storageKey = '_sf2_attributes', |
| 30 |
) { |
| 31 |
} |
| 32 |
|
| 33 |
public function getName(): string |
| 34 |
{ |
| 35 |
return $this->name; |
| 36 |
} |
| 37 |
|
| 38 |
public function setName(string $name): void |
| 39 |
{ |
| 40 |
$this->name = $name; |
| 41 |
} |
| 42 |
|
| 43 |
public function initialize(array &$attributes): void |
| 44 |
{ |
| 45 |
$this->attributes = &$attributes; |
| 46 |
} |
| 47 |
|
| 48 |
public function getStorageKey(): string |
| 49 |
{ |
| 50 |
return $this->storageKey; |
| 51 |
} |
| 52 |
|
| 53 |
public function has(string $name): bool |
| 54 |
{ |
| 55 |
return \array_key_exists($name, $this->attributes); |
| 56 |
} |
| 57 |
|
| 58 |
public function get(string $name, mixed $default = null): mixed |
| 59 |
{ |
| 60 |
return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default; |
| 61 |
} |
| 62 |
|
| 63 |
public function set(string $name, mixed $value): void |
| 64 |
{ |
| 65 |
$this->attributes[$name] = $value; |
| 66 |
} |
| 67 |
|
| 68 |
public function all(): array |
| 69 |
{ |
| 70 |
return $this->attributes; |
| 71 |
} |
| 72 |
|
| 73 |
public function replace(array $attributes): void |
| 74 |
{ |
| 75 |
$this->attributes = []; |
| 76 |
foreach ($attributes as $key => $value) { |
| 77 |
$this->set($key, $value); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
public function remove(string $name): mixed |
| 82 |
{ |
| 83 |
$retval = null; |
| 84 |
if (\array_key_exists($name, $this->attributes)) { |
| 85 |
$retval = $this->attributes[$name]; |
| 86 |
unset($this->attributes[$name]); |
| 87 |
} |
| 88 |
|
| 89 |
return $retval; |
| 90 |
} |
| 91 |
|
| 92 |
public function clear(): mixed |
| 93 |
{ |
| 94 |
$return = $this->attributes; |
| 95 |
$this->attributes = []; |
| 96 |
|
| 97 |
return $return; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public function getIterator(): \ArrayIterator |
| 106 |
{ |
| 107 |
return new \ArrayIterator($this->attributes); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public function count(): int |
| 114 |
{ |
| 115 |
return \count($this->attributes); |
| 116 |
} |
| 117 |
} |