Debian Codegraph @

lib/3rdParty/composer/symfony/http-foundation/Session/Storage/Proxy/AbstractProxy.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\Storage\Proxy;
13
14 /**
15 * @author Drak <[email protected]>
16 */
17 abstract class AbstractProxy
18 {
19 protected bool $wrapper = false;
20
21 protected ?string $saveHandlerName = null;
22
23 /**
24 * Gets the session.save_handler name.
25 */
26 public function getSaveHandlerName(): ?string
27 {
28 return $this->saveHandlerName;
29 }
30
31 /**
32 * Is this proxy handler and instance of \SessionHandlerInterface.
33 */
34 public function isSessionHandlerInterface(): bool
35 {
36 return $this instanceof \SessionHandlerInterface;
37 }
38
39 /**
40 * Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
41 */
42 public function isWrapper(): bool
43 {
44 return $this->wrapper;
45 }
46
47 /**
48 * Has a session started?
49 */
50 public function isActive(): bool
51 {
52 return \PHP_SESSION_ACTIVE === session_status();
53 }
54
55 /**
56 * Gets the session ID.
57 */
58 public function getId(): string
59 {
60 return session_id();
61 }
62
63 /**
64 * Sets the session ID.
65 *
66 * @throws \LogicException
67 */
68 public function setId(string $id): void
69 {
70 if ($this->isActive()) {
71 throw new \LogicException('Cannot change the ID of an active session.');
72 }
73
74 session_id($id);
75 }
76
77 /**
78 * Gets the session name.
79 */
80 public function getName(): string
81 {
82 return session_name();
83 }
84
85 /**
86 * Sets the session name.
87 *
88 * @throws \LogicException
89 */
90 public function setName(string $name): void
91 {
92 if ($this->isActive()) {
93 throw new \LogicException('Cannot change the name of an active session.');
94 }
95
96 session_name($name);
97 }
98 }