Fixes improper code in __get (code was inadvertantly calling __isset).
authorVincent Zanotti <vincent.zanotti@polytechnique.org>
Sun, 24 Aug 2008 15:30:59 +0000 (17:30 +0200)
committerVincent Zanotti <vincent.zanotti@polytechnique.org>
Sun, 24 Aug 2008 15:30:59 +0000 (17:30 +0200)
Adds a public method for extending the user secondary properties.

Signed-off-by: Vincent Zanotti <vincent.zanotti@polytechnique.org>
classes/pluser.php

index 86cdf26..1aa5814 100644 (file)
@@ -177,7 +177,7 @@ abstract class PlUser
 
     public function __get($name)
     {
-        if (isset($this->$name)) {
+        if (property_exists($this, $name)) {
             return $this->$name;
         }
 
@@ -190,7 +190,7 @@ abstract class PlUser
 
     public function __isset($name)
     {
-        return isset($this->$name) || isset($this->data[$name]);
+        return property_exists($this, $name) || isset($this->data[$name]);
     }
 
     /**
@@ -213,6 +213,21 @@ abstract class PlUser
         $this->data = array_merge($this->data, $values);
     }
 
+    /**
+     * Adds properties to the object; this method does not allow the caller to
+     * update core properties (id, ...).
+     *
+     * @param $values An associative array of non-core properties.
+     */
+    public function addProperties(array $values)
+    {
+        foreach ($values as $key => $value) {
+            if (!property_exists($this, $key)) {
+                $this->data[$key] = $value;
+            }
+        }
+    }
+
 
     /**
      * Build the permissions flags for the user.