From: Raphaël Barrois Date: Mon, 8 Mar 2010 01:00:38 +0000 (+0100) Subject: Add PlIteratorUtils::getObjectProperty callback X-Git-Tag: core/1.1.0~58 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ce06a3eab5be89f8d281c6397da2c041720e929a;p=platal.git Add PlIteratorUtils::getObjectProperty callback Signed-off-by: Raphaël Barrois --- diff --git a/classes/pliteratorutils.php b/classes/pliteratorutils.php index db10927..e24ab81 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 arrayValueCallback($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: ?>