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