PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / http-foundation / Session / Session.php
matomo / app / vendor / prefixed / symfony / http-foundation / Session Last commit date
Attribute 1 year ago Flash 2 years ago Storage 1 year ago Session.php 1 year ago SessionBagInterface.php 2 years ago SessionBagProxy.php 1 year ago SessionFactory.php 2 years ago SessionFactoryInterface.php 2 years ago SessionInterface.php 1 year ago SessionUtils.php 1 year ago
Session.php
250 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 namespace Matomo\Dependencies\Symfony\Component\HttpFoundation\Session;
12
13 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
14 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
15 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
16 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
17 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
18 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
19 // Help opcache.preload discover always-needed symbols
20 class_exists(AttributeBag::class);
21 class_exists(FlashBag::class);
22 class_exists(SessionBagProxy::class);
23 /**
24 * @author Fabien Potencier <fabien@symfony.com>
25 * @author Drak <drak@zikula.org>
26 *
27 * @implements \IteratorAggregate<string, mixed>
28 */
29 class Session implements SessionInterface, \IteratorAggregate, \Countable
30 {
31 protected $storage;
32 private $flashName;
33 private $attributeName;
34 private $data = [];
35 private $usageIndex = 0;
36 private $usageReporter;
37 public function __construct(?SessionStorageInterface $storage = null, ?AttributeBagInterface $attributes = null, ?FlashBagInterface $flashes = null, ?callable $usageReporter = null)
38 {
39 $this->storage = $storage ?? new NativeSessionStorage();
40 $this->usageReporter = $usageReporter;
41 $attributes = $attributes ?? new AttributeBag();
42 $this->attributeName = $attributes->getName();
43 $this->registerBag($attributes);
44 $flashes = $flashes ?? new FlashBag();
45 $this->flashName = $flashes->getName();
46 $this->registerBag($flashes);
47 }
48 /**
49 * {@inheritdoc}
50 */
51 public function start()
52 {
53 return $this->storage->start();
54 }
55 /**
56 * {@inheritdoc}
57 */
58 public function has(string $name)
59 {
60 return $this->getAttributeBag()->has($name);
61 }
62 /**
63 * {@inheritdoc}
64 */
65 public function get(string $name, $default = null)
66 {
67 return $this->getAttributeBag()->get($name, $default);
68 }
69 /**
70 * {@inheritdoc}
71 */
72 public function set(string $name, $value)
73 {
74 $this->getAttributeBag()->set($name, $value);
75 }
76 /**
77 * {@inheritdoc}
78 */
79 public function all()
80 {
81 return $this->getAttributeBag()->all();
82 }
83 /**
84 * {@inheritdoc}
85 */
86 public function replace(array $attributes)
87 {
88 $this->getAttributeBag()->replace($attributes);
89 }
90 /**
91 * {@inheritdoc}
92 */
93 public function remove(string $name)
94 {
95 return $this->getAttributeBag()->remove($name);
96 }
97 /**
98 * {@inheritdoc}
99 */
100 public function clear()
101 {
102 $this->getAttributeBag()->clear();
103 }
104 /**
105 * {@inheritdoc}
106 */
107 public function isStarted()
108 {
109 return $this->storage->isStarted();
110 }
111 /**
112 * Returns an iterator for attributes.
113 *
114 * @return \ArrayIterator<string, mixed>
115 */
116 #[\ReturnTypeWillChange]
117 public function getIterator()
118 {
119 return new \ArrayIterator($this->getAttributeBag()->all());
120 }
121 /**
122 * Returns the number of attributes.
123 *
124 * @return int
125 */
126 #[\ReturnTypeWillChange]
127 public function count()
128 {
129 return \count($this->getAttributeBag()->all());
130 }
131 public function &getUsageIndex() : int
132 {
133 return $this->usageIndex;
134 }
135 /**
136 * @internal
137 */
138 public function isEmpty() : bool
139 {
140 if ($this->isStarted()) {
141 ++$this->usageIndex;
142 if ($this->usageReporter && 0 <= $this->usageIndex) {
143 ($this->usageReporter)();
144 }
145 }
146 foreach ($this->data as &$data) {
147 if (!empty($data)) {
148 return \false;
149 }
150 }
151 return \true;
152 }
153 /**
154 * {@inheritdoc}
155 */
156 public function invalidate(?int $lifetime = null)
157 {
158 $this->storage->clear();
159 return $this->migrate(\true, $lifetime);
160 }
161 /**
162 * {@inheritdoc}
163 */
164 public function migrate(bool $destroy = \false, ?int $lifetime = null)
165 {
166 return $this->storage->regenerate($destroy, $lifetime);
167 }
168 /**
169 * {@inheritdoc}
170 */
171 public function save()
172 {
173 $this->storage->save();
174 }
175 /**
176 * {@inheritdoc}
177 */
178 public function getId()
179 {
180 return $this->storage->getId();
181 }
182 /**
183 * {@inheritdoc}
184 */
185 public function setId(string $id)
186 {
187 if ($this->storage->getId() !== $id) {
188 $this->storage->setId($id);
189 }
190 }
191 /**
192 * {@inheritdoc}
193 */
194 public function getName()
195 {
196 return $this->storage->getName();
197 }
198 /**
199 * {@inheritdoc}
200 */
201 public function setName(string $name)
202 {
203 $this->storage->setName($name);
204 }
205 /**
206 * {@inheritdoc}
207 */
208 public function getMetadataBag()
209 {
210 ++$this->usageIndex;
211 if ($this->usageReporter && 0 <= $this->usageIndex) {
212 ($this->usageReporter)();
213 }
214 return $this->storage->getMetadataBag();
215 }
216 /**
217 * {@inheritdoc}
218 */
219 public function registerBag(SessionBagInterface $bag)
220 {
221 $this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->usageIndex, $this->usageReporter));
222 }
223 /**
224 * {@inheritdoc}
225 */
226 public function getBag(string $name)
227 {
228 $bag = $this->storage->getBag($name);
229 return method_exists($bag, 'getBag') ? $bag->getBag() : $bag;
230 }
231 /**
232 * Gets the flashbag interface.
233 *
234 * @return FlashBagInterface
235 */
236 public function getFlashBag()
237 {
238 return $this->getBag($this->flashName);
239 }
240 /**
241 * Gets the attributebag interface.
242 *
243 * Note that this method was added to help with IDE autocompletion.
244 */
245 private function getAttributeBag() : AttributeBagInterface
246 {
247 return $this->getBag($this->attributeName);
248 }
249 }
250