diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-04-14 11:29:44 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-04-14 11:29:54 +0200 |
commit | 3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472 (patch) | |
tree | a1e466f4875a4766124427f91a5db35c57e0fffd /lib/search.php | |
parent | 8ed4606685f93f5fea002aecaf5279f482e78115 (diff) | |
download | nextcloud-server-3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472.tar.gz nextcloud-server-3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472.zip |
improve flexibility of search providers a bit
Diffstat (limited to 'lib/search.php')
-rw-r--r-- | lib/search.php | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/search.php b/lib/search.php index 6b33fa38140..12055418687 100644 --- a/lib/search.php +++ b/lib/search.php @@ -26,13 +26,22 @@ */ class OC_Search{ static private $providers=array(); + static private $registeredProviders=array(); + + /** + * remove all registered search providers + */ + public static function clearProviders(){ + self::$providers=array(); + self::$registeredProviders=array(); + } /** * register a new search provider to be used * @param string $provider class name of a OC_Search_Provider */ - public static function registerProvider($provider){ - self::$providers[]=$provider; + public static function registerProvider($class,$options=array()){ + self::$registeredProviders[]=array('class'=>$class,'options'=>$options); } /** @@ -41,10 +50,25 @@ class OC_Search{ * @return array An array of OC_Search_Result's */ public static function search($query){ + self::initProviders(); $results=array(); foreach(self::$providers as $provider){ - $results=array_merge($results, $provider::search($query)); + $results=array_merge($results, $provider->search($query)); } return $results; } + + /** + * create instances of all the registered search providers + */ + private static function initProviders(){ + if(count(self::$providers)>0){ + return; + } + foreach(self::$registeredProviders as $provider){ + $class=$provider['class']; + $options=$provider['options']; + self::$providers[]=new $class($options); + } + } } |