X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fpliteratorutils.php;h=dfa8a36fabd91b016a67f27d0afd2cc1935e82be;hb=5d0c351e87013f73d7176d55814dc650f91a2939;hp=db1092745f7a31faa1dfba8d8cac8974378c7652;hpb=381a28e9a41563eb2c440fb3115aa58f4f1a6ed1;p=platal.git diff --git a/classes/pliteratorutils.php b/classes/pliteratorutils.php index db10927..dfa8a36 100644 --- a/classes/pliteratorutils.php +++ b/classes/pliteratorutils.php @@ -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: ?>