| 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 |
/** |
| 20 |
* Flag if handler wraps an internal PHP session handler (using \SessionHandler). |
| 21 |
* |
| 22 |
* @var bool |
| 23 |
*/ |
| 24 |
protected $wrapper = false; |
| 25 |
|
| 26 |
/** |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
protected $saveHandlerName; |
| 30 |
|
| 31 |
/** |
| 32 |
* Gets the session.save_handler name. |
| 33 |
* |
| 34 |
* @return string|null |
| 35 |
*/ |
| 36 |
public function getSaveHandlerName() |
| 37 |
{ |
| 38 |
return $this->saveHandlerName; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Is this proxy handler and instance of \SessionHandlerInterface. |
| 43 |
* |
| 44 |
* @return bool |
| 45 |
*/ |
| 46 |
public function isSessionHandlerInterface() |
| 47 |
{ |
| 48 |
return $this instanceof \SessionHandlerInterface; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler. |
| 53 |
* |
| 54 |
* @return bool |
| 55 |
*/ |
| 56 |
public function isWrapper() |
| 57 |
{ |
| 58 |
return $this->wrapper; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Has a session started? |
| 63 |
* |
| 64 |
* @return bool |
| 65 |
*/ |
| 66 |
public function isActive() |
| 67 |
{ |
| 68 |
return \PHP_SESSION_ACTIVE === session_status(); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Gets the session ID. |
| 73 |
* |
| 74 |
* @return string |
| 75 |
*/ |
| 76 |
public function getId() |
| 77 |
{ |
| 78 |
return session_id(); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Sets the session ID. |
| 83 |
* |
| 84 |
* @throws \LogicException |
| 85 |
*/ |
| 86 |
public function setId(string $id) |
| 87 |
{ |
| 88 |
if ($this->isActive()) { |
| 89 |
throw new \LogicException('Cannot change the ID of an active session.'); |
| 90 |
} |
| 91 |
|
| 92 |
session_id($id); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Gets the session name. |
| 97 |
* |
| 98 |
* @return string |
| 99 |
*/ |
| 100 |
public function getName() |
| 101 |
{ |
| 102 |
return session_name(); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Sets the session name. |
| 107 |
* |
| 108 |
* @throws \LogicException |
| 109 |
*/ |
| 110 |
public function setName(string $name) |
| 111 |
{ |
| 112 |
if ($this->isActive()) { |
| 113 |
throw new \LogicException('Cannot change the name of an active session.'); |
| 114 |
} |
| 115 |
|
| 116 |
session_name($name); |
| 117 |
} |
| 118 |
} |
| 119 |
|