1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Core
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Session abstaract class
29: *
30: * @category Mage
31: * @package Mage_Core
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: abstract class Mage_Core_Model_Session_Abstract_Zend extends Varien_Object
35: {
36: /**
37: * Session namespace object
38: *
39: * @var Zend_Session_Namespace
40: */
41: protected $_namespace;
42:
43: public function getNamespace()
44: {
45: return $this->_namespace;
46: }
47:
48: public function start()
49: {
50: Varien_Profiler::start(__METHOD__.'/setOptions');
51: $options = array(
52: 'save_path'=>Mage::getBaseDir('session'),
53: 'use_only_cookies'=>'off',
54: 'throw_startup_exceptions' => E_ALL ^ E_NOTICE,
55: );
56: if ($this->getCookieDomain()) {
57: $options['cookie_domain'] = $this->getCookieDomain();
58: }
59: if ($this->getCookiePath()) {
60: $options['cookie_path'] = $this->getCookiePath();
61: }
62: if ($this->getCookieLifetime()) {
63: $options['cookie_lifetime'] = $this->getCookieLifetime();
64: }
65: Zend_Session::setOptions($options);
66: Varien_Profiler::stop(__METHOD__.'/setOptions');
67: /*
68: Varien_Profiler::start(__METHOD__.'/setHandler');
69: $sessionResource = Mage::getResourceSingleton('core/session');
70: if ($sessionResource->hasConnection()) {
71: Zend_Session::setSaveHandler($sessionResource);
72: }
73: Varien_Profiler::stop(__METHOD__.'/setHandler');
74: */
75: Varien_Profiler::start(__METHOD__.'/start');
76: Zend_Session::start();
77: Varien_Profiler::stop(__METHOD__.'/start');
78:
79: return $this;
80: }
81:
82: /**
83: * Initialization session namespace
84: *
85: * @param string $namespace
86: */
87: public function init($namespace)
88: {
89: if (!Zend_Session::sessionExists()) {
90: $this->start();
91: }
92:
93: Varien_Profiler::start(__METHOD__.'/init');
94: $this->_namespace = new Zend_Session_Namespace($namespace, Zend_Session_Namespace::SINGLE_INSTANCE);
95: Varien_Profiler::stop(__METHOD__.'/init');
96: return $this;
97: }
98:
99: /**
100: * Redeclaration object setter
101: *
102: * @param string $key
103: * @param mixed $value
104: * @return Mage_Core_Model_Session_Abstract
105: */
106: public function setData($key, $value='', $isChanged = false)
107: {
108: if (!$this->_namespace->data) {
109: $this->_namespace->data = new Varien_Object();
110: }
111: $this->_namespace->data->setData($key, $value, $isChanged);
112: return $this;
113: }
114:
115: /**
116: * Redeclaration object getter
117: *
118: * @param string $var
119: * @param bool $clear
120: * @return mixed
121: */
122: public function getData($var=null, $clear=false)
123: {
124: if (!$this->_namespace->data) {
125: $this->_namespace->data = new Varien_Object();
126: }
127:
128: $data = $this->_namespace->data->getData($var);
129:
130: if ($clear) {
131: $this->_namespace->data->unsetData($var);
132: }
133:
134: return $data;
135: }
136:
137: /**
138: * Cleare session data
139: *
140: * @return Mage_Core_Model_Session_Abstract
141: */
142: public function unsetAll()
143: {
144: $this->_namespace->unsetAll();
145: return $this;
146: }
147:
148: /**
149: * Retrieve current session identifier
150: *
151: * @return string
152: */
153: public function getSessionId()
154: {
155: return Zend_Session::getId();
156: }
157:
158: public function setSessionId($id=null)
159: {
160: if (!is_null($id)) {
161: Zend_Session::setId($id);
162: }
163: return $this;
164: }
165:
166: /**
167: * Regenerate session Id
168: *
169: * @return Mage_Core_Model_Session_Abstract_Zend
170: */
171: public function regenerateSessionId()
172: {
173: Zend_Session::regenerateId();
174: return $this;
175: }
176: }
177: