Debian Codegraph @

lib/3rdParty/composer/symfony/http-foundation/Session/SessionBagProxy.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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;
13
14 /**
15 * @author Nicolas Grekas <[email protected]>
16 *
17 * @internal
18 */
19 final class SessionBagProxy implements SessionBagInterface
20 {
21 private array $data;
22 private ?int $usageIndex;
23 private ?\Closure $usageReporter;
24
25 public function __construct(
26 private SessionBagInterface $bag,
27 array &$data,
28 ?int &$usageIndex,
29 ?callable $usageReporter,
30 ) {
31 $this->bag = $bag;
32 $this->data = &$data;
33 $this->usageIndex = &$usageIndex;
34 $this->usageReporter = null === $usageReporter ? null : $usageReporter(...);
35 }
36
37 public function getBag(): SessionBagInterface
38 {
39 ++$this->usageIndex;
40 if ($this->usageReporter && 0 <= $this->usageIndex) {
41 ($this->usageReporter)();
42 }
43
44 return $this->bag;
45 }
46
47 public function isEmpty(): bool
48 {
49 if (!isset($this->data[$this->bag->getStorageKey()])) {
50 return true;
51 }
52 ++$this->usageIndex;
53 if ($this->usageReporter && 0 <= $this->usageIndex) {
54 ($this->usageReporter)();
55 }
56
57 return empty($this->data[$this->bag->getStorageKey()]);
58 }
59
60 public function getName(): string
61 {
62 return $this->bag->getName();
63 }
64
65 public function initialize(array &$array): void
66 {
67 ++$this->usageIndex;
68 if ($this->usageReporter && 0 <= $this->usageIndex) {
69 ($this->usageReporter)();
70 }
71
72 $this->data[$this->bag->getStorageKey()] = &$array;
73
74 $this->bag->initialize($array);
75 }
76
77 public function getStorageKey(): string
78 {
79 return $this->bag->getStorageKey();
80 }
81
82 public function clear(): mixed
83 {
84 return $this->bag->clear();
85 }
86 }