From 7c8d7022042ef34cbf8c16531a3b5eaecf46bfd2 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Mon, 22 Dec 2008 00:04:26 +0100 Subject: [PATCH] Checks the current logger is still valid in S::logger(). Signed-off-by: Florent Bruneau --- classes/pllogger.php | 21 +++++++++++++++++++++ classes/s.php | 9 ++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/classes/pllogger.php b/classes/pllogger.php index 6505a4d..924fd62 100644 --- a/classes/pllogger.php +++ b/classes/pllogger.php @@ -36,6 +36,13 @@ abstract class PlLogger */ abstract public function log($action, $data = null); + /** Check validity of the logger. + * + * @param $uid the uid of the current session. + * @return TRUE if the logger can still be used. + */ + abstract public function isValid($uid); + /** Build a logger. */ public static function get($uid, $suid = 0) @@ -47,17 +54,31 @@ abstract class PlLogger return new DummyLogger($uid, $suid); } } + + /** Return a dummy logger. + */ + public static function dummy($uid, $suid = 0) { + return new DummyLogger($uid, $suid); + } } class DummyLogger extends PlLogger { + private $uid; + public function __construct($uid, $suid = 0) { + $this->uid = $uid; } public function log($action, $data = null) { } + + public function isValid($uid) + { + return $uid == $this->uid; + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/classes/s.php b/classes/s.php index 0a9c1d7..e14c440 100644 --- a/classes/s.php +++ b/classes/s.php @@ -74,12 +74,15 @@ class S public static function logger($uid = null) { - if (!S::has('log')) { + $uid = S::i('uid', $uid); + if (!S::has('log') || !S::v('log')->isValid($uid)) { if (S::has('suid')) { $suid = S::v('suid'); - S::set('log', PlLogger::get(S::v('uid', $uid), $suid['uid'])); + S::set('log', PlLogger::get(S::i('uid', $uid), $suid['uid'])); } else if (S::has('uid') || $uid) { - S::set('log', PlLogger::get(S::v('uid', $uid))); + S::set('log', PlLogger::get(S::i('uid', $uid))); + } else { + S::set('log', PlLogger::dummy($uid)); } } return S::v('log'); -- 2.1.4