From 47257616c6d9dd912c156acb48a3af114c93feb4 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 30 Mar 2013 14:20:00 +0200 Subject: [PATCH] automatically unserialize session data --- ipf/session/middleware.php | 2 +- ipf/session/models/Session.php | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ipf/session/middleware.php b/ipf/session/middleware.php index f70674f..65840ed 100644 --- a/ipf/session/middleware.php +++ b/ipf/session/middleware.php @@ -93,4 +93,4 @@ function IPF_Session_Middleware_ContextPreProcessor($request) Pluf_Signal::connect('Pluf_Template_Context_Request::construct', array('Pluf_Middleware_Session', 'processContext')); -*/ \ No newline at end of file +*/ diff --git a/ipf/session/models/Session.php b/ipf/session/models/Session.php index 5191504..5054e42 100644 --- a/ipf/session/models/Session.php +++ b/ipf/session/models/Session.php @@ -5,12 +5,26 @@ class Session extends BaseSession public $data = array(); public $touched = false; - function clear(){ + function clear() + { $this->data = array(); $this->touched = true; } - function setData($key, $value=null){ + function getSessionData() + { + return unserialize($this->session_data); + } + + private function unserializeData() + { + if (!$this->data) + $this->data = $this->getSessionData(); + } + + function setData($key, $value=null) + { + $this->unserializeData(); if (is_null($value)) { unset($this->data[$key]); } else { @@ -19,14 +33,12 @@ class Session extends BaseSession $this->touched = true; } - function getSessionData(){ - return unserialize($this->session_data); - } - - function getData($key=null, $default=''){ - if (is_null($key)) + function getData($key=null, $default='') + { + if (is_null($key)) return parent::getData(); + $this->unserializeData(); if (isset($this->data[$key])) { return $this->data[$key]; } else { @@ -48,4 +60,5 @@ class Session extends BaseSession } $this->expire_data = gmdate('Y-m-d H:i:s', time()+31536000); } -} \ No newline at end of file +} + -- 2.49.0