summaryrefslogtreecommitdiff
path: root/inc/search.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/search.php')
-rw-r--r--inc/search.php33
1 files changed, 31 insertions, 2 deletions
diff --git a/inc/search.php b/inc/search.php
index 254848d4b..5de5a1f47 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -15,6 +15,11 @@
* This function recurses into a given base directory
* and calls the supplied function for each file and directory
*
+ * @param array ref $data The results of the search are stored here
+ * @param string $base Where to start the search
+ * @param callback $func Callback (function name or arayy with object,method)
+ * @param string $dir Current directory beyond $base
+ * @param int $lvl Recursion Level
* @author Andreas Gohr <andi@splitbrain.org>
*/
function search(&$data,$base,$func,$opts,$dir='',$lvl=1){
@@ -41,17 +46,41 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1){
//give directories to userfunction then recurse
foreach($dirs as $dir){
- if ($func($data,$base,$dir,'d',$lvl,$opts)){
+ if (search_callback($func,$data,$base,$dir,'d',$lvl,$opts)){
search($data,$base,$func,$opts,$dir,$lvl+1);
}
}
//now handle the files
foreach($files as $file){
- $func($data,$base,$file,'f',$lvl,$opts);
+ search_callback($func,$data,$base,$file,'f',$lvl,$opts);
}
}
/**
+ * Used to run the a user callback
+ *
+ * Makes sure the $data array is passed by reference (unlike when using
+ * call_user_func())
+ *
+ * @todo If this can be generalized it may be useful elsewhere in the code
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function search_callback($func,&$data,$base,$file,$type,$lvl,$opts){
+ if(is_array($func)){
+ if(is_object($func[0])){
+ // instanciated object
+ return $func[0]->$func[1]($data,$base,$file,$type,$lvl,$opts);
+ }else{
+ // static call
+ $f = $func[0].'::'.$func[1];
+ return $f($data,$base,$file,$type,$lvl,$opts);
+ }
+ }
+ // simple function call
+ return $func($data,$base,$file,$type,$lvl,$opts);
+}
+
+/**
* The following functions are userfunctions to use with the search
* function above. This function is called for every found file or
* directory. When a directory is given to the function it has to