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:
12: namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
13:
14: /**
15: * AbstractProxy.
16: *
17: * @author Drak <drak@zikula.org>
18: */
19: abstract class AbstractProxy
20: {
21: /**
22: * Flag if handler wraps an internal PHP session handler (using \SessionHandler).
23: *
24: * @var boolean
25: */
26: protected $wrapper = false;
27:
28: /**
29: * @var boolean
30: */
31: protected $active = false;
32:
33: /**
34: * @var string
35: */
36: protected $saveHandlerName;
37:
38: /**
39: * Gets the session.save_handler name.
40: *
41: * @return string
42: */
43: public function getSaveHandlerName()
44: {
45: return $this->saveHandlerName;
46: }
47:
48: /**
49: * Is this proxy handler and instance of \SessionHandlerInterface.
50: *
51: * @return boolean
52: */
53: public function isSessionHandlerInterface()
54: {
55: return ($this instanceof \SessionHandlerInterface);
56: }
57:
58: /**
59: * Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
60: *
61: * @return Boolean
62: */
63: public function isWrapper()
64: {
65: return $this->wrapper;
66: }
67:
68: /**
69: * Has a session started?
70: *
71: * @return Boolean
72: */
73: public function isActive()
74: {
75: return $this->active;
76: }
77:
78: /**
79: * Sets the active flag.
80: *
81: * @param Boolean $flag
82: */
83: public function setActive($flag)
84: {
85: $this->active = (bool) $flag;
86: }
87:
88: /**
89: * Gets the session ID.
90: *
91: * @return string
92: */
93: public function getId()
94: {
95: return session_id();
96: }
97:
98: /**
99: * Sets the session ID.
100: *
101: * @param string $id
102: *
103: * @throws \LogicException
104: */
105: public function setId($id)
106: {
107: if ($this->isActive()) {
108: throw new \LogicException('Cannot change the ID of an active session');
109: }
110:
111: session_id($id);
112: }
113:
114: /**
115: * Gets the session name.
116: *
117: * @return string
118: */
119: public function getName()
120: {
121: return session_name();
122: }
123:
124: /**
125: * Sets the session name.
126: *
127: * @param string $name
128: *
129: * @throws \LogicException
130: */
131: public function setName($name)
132: {
133: if ($this->isActive()) {
134: throw new \LogicException('Cannot change the name of an active session');
135: }
136:
137: session_name($name);
138: }
139: }
140: