From ce06a3eab5be89f8d281c6397da2c041720e929a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 8 Mar 2010 02:00:38 +0100 Subject: [PATCH] Add PlIteratorUtils::getObjectProperty callback MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/pliteratorutils.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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: ?> -- 2.1.4