Checks the current logger is still valid in S::logger().
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 21 Dec 2008 23:04:26 +0000 (00:04 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 21 Dec 2008 23:04:26 +0000 (00:04 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/pllogger.php
classes/s.php

index 6505a4d..924fd62 100644 (file)
@@ -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:
index 0a9c1d7..e14c440 100644 (file)
@@ -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');