Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy; Chris@0: Chris@0: /** Chris@0: * @author Drak Chris@0: */ Chris@0: abstract class AbstractProxy Chris@0: { Chris@0: /** Chris@0: * Flag if handler wraps an internal PHP session handler (using \SessionHandler). Chris@0: * Chris@0: * @var bool Chris@0: */ Chris@0: protected $wrapper = false; Chris@0: Chris@0: /** Chris@0: * @var string Chris@0: */ Chris@0: protected $saveHandlerName; Chris@0: Chris@0: /** Chris@0: * Gets the session.save_handler name. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getSaveHandlerName() Chris@0: { Chris@0: return $this->saveHandlerName; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Is this proxy handler and instance of \SessionHandlerInterface. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isSessionHandlerInterface() Chris@0: { Chris@0: return $this instanceof \SessionHandlerInterface; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns true if this handler wraps an internal PHP session save handler using \SessionHandler. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isWrapper() Chris@0: { Chris@0: return $this->wrapper; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Has a session started? Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isActive() Chris@0: { Chris@0: return \PHP_SESSION_ACTIVE === session_status(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the session ID. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getId() Chris@0: { Chris@0: return session_id(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the session ID. Chris@0: * Chris@0: * @param string $id Chris@0: * Chris@0: * @throws \LogicException Chris@0: */ Chris@0: public function setId($id) Chris@0: { Chris@0: if ($this->isActive()) { Chris@0: throw new \LogicException('Cannot change the ID of an active session'); Chris@0: } Chris@0: Chris@0: session_id($id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the session name. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return session_name(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the session name. Chris@0: * Chris@0: * @param string $name Chris@0: * Chris@0: * @throws \LogicException Chris@0: */ Chris@0: public function setName($name) Chris@0: { Chris@0: if ($this->isActive()) { Chris@0: throw new \LogicException('Cannot change the name of an active session'); Chris@0: } Chris@0: Chris@0: session_name($name); Chris@0: } Chris@0: }