$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.
return ($this->source->last() && $this->next == null);
}
+ public function first()
+ {
+ return $this->source->first();
+ }
+
// Called by a subiterator to "rewind" the core iterator
public function setNext($item)
{
return $this->over;
}
+ public function first()
+ {
+ return false;
+ }
+
}
// Wrapper class for 'arrayValueCallback' (get field $key of the given array)
public function get(array $arr)
{
- if (array_key_exists($key, $arr)) {
- return $arr[$key];
+ if (array_key_exists($this->key, $arr)) {
+ return $arr[$this->key];
} else {
return null;
}
}
}
+// 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:
?>