Add basic include for unit tests.
[platal.git] / classes / pliteratorutils.php
index db10927..dfa8a36 100644 (file)
@@ -105,6 +105,16 @@ class PlIteratorUtils
         $callback = new _GetArrayValueCallback($key);
         return array($callback, 'get');
     }
+
+    /** Returns the callback for '$x -> $x->prop';
+     * @param $property The property to retrieve
+     * @return a callback
+     */
+    public static function objectPropertyCallback($property)
+    {
+        $callback = new _GetObjectPropertyCallback($property);
+        return array($callback, 'get');
+    }
 }
 
 /** Iterates over an array.
@@ -550,5 +560,22 @@ class _GetArrayValueCallback
     }
 }
 
+// Wrapper class for 'objectPropertyCallback' (get property ->$blah of the given object)
+class _GetObjectPropertyCallback
+{
+    private $property;
+
+    public function __construct($property)
+    {
+        $this->property = $property;
+    }
+
+    public function get($obj)
+    {
+        $p = $this->property;
+        return @$obj->$p;
+    }
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>