summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-06-06 01:17:02 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-06-06 01:17:02 +0200
commitaaf0d131718dc9079a5b3717276455f8701feeea (patch)
treeca915a5012b5d107d8d201d25a365a312e71a095
parent5034bd1b129b75e7b571cb0ed239d02010c806f7 (diff)
downloadnextcloud-server-aaf0d131718dc9079a5b3717276455f8701feeea.tar.gz
nextcloud-server-aaf0d131718dc9079a5b3717276455f8701feeea.zip
make search non-static, add ISearch to server container, make legacy a static wrapper for it, move provider and result to public api
-rw-r--r--lib/private/legacy/search.php41
-rw-r--r--lib/private/search.php49
-rw-r--r--lib/private/search/provider/file.php4
-rw-r--r--lib/private/search/result/file.php2
-rw-r--r--lib/private/server.php10
-rw-r--r--lib/public/isearch.php57
-rw-r--r--lib/public/iservercontainer.php8
-rw-r--r--lib/public/search/provider.php (renamed from lib/private/search/provider.php)4
-rw-r--r--lib/public/search/result.php (renamed from lib/private/search/result.php)2
9 files changed, 146 insertions, 31 deletions
diff --git a/lib/private/legacy/search.php b/lib/private/legacy/search.php
index e6396020225..f77b43be2e0 100644
--- a/lib/private/legacy/search.php
+++ b/lib/private/legacy/search.php
@@ -24,6 +24,45 @@
* provides an interface to all search providers
* @deprecated see lib/search.php
*/
-class OC_Search extends \OC\Search{
+class OC_Search {
+ /**
+ * @return \OCP\ISearch
+ */
+ private static function getSearch() {
+ return \OC::$server->getSearch();
+ }
+
+ /**
+ * Search all providers for $query
+ * @param string $query
+ * @return array An array of OCP\Search\Result's
+ */
+ public static function search($query) {
+ return self::getSearch()->search($query);
+ }
+
+ /**
+ * Register a new search provider to search with
+ * @param string $class class name of a OCP\Search\Provider
+ * @param array $options optional
+ */
+ public static function registerProvider($class, $options = array()) {
+ return self::getSearch()->registerProvider($class, $options);
+ }
+
+ /**
+ * Remove one existing search provider
+ * @param string $provider class name of a OCP\Search\Provider
+ */
+ public static function removeProvider($provider) {
+ return self::getSearch()->removeProvider($provider);
+ }
+
+ /**
+ * Remove all registered search providers
+ */
+ public static function clearProviders() {
+ return self::getSearch()->clearProviders();
+ }
}
diff --git a/lib/private/search.php b/lib/private/search.php
index 8ac9e9fdf33..bcaebdddd9c 100644
--- a/lib/private/search.php
+++ b/lib/private/search.php
@@ -21,27 +21,28 @@
*/
namespace OC;
-use OC\Search\Provider;
+use OCP\Search\Provider;
+use OCP\ISearch;
/**
* Provide an interface to all search providers
*/
-class Search {
+class Search implements ISearch {
- static private $providers=array();
- static private $registeredProviders=array();
+ private $providers = array();
+ private $registeredProviders = array();
/**
* Search all providers for $query
* @param string $query
* @return array An array of OC\Search\Result's
*/
- public static function search($query) {
- self::initProviders();
- $results=array();
- foreach(self::$providers as $provider) {
+ public function search($query) {
+ $this->initProviders();
+ $results = array();
+ foreach($this->providers as $provider) {
/** @var $provider Provider */
- $results=array_merge($results, $provider->search($query));
+ $results = array_merge($results, $provider->search($query));
}
return $results;
}
@@ -49,24 +50,24 @@ class Search {
/**
* Remove all registered search providers
*/
- public static function clearProviders() {
- self::$providers=array();
- self::$registeredProviders=array();
+ public function clearProviders() {
+ $this->providers=array();
+ $this->registeredProviders=array();
}
/**
* Remove one existing search provider
* @param string $provider class name of a OC\Search\Provider
*/
- public static function removeProvider($provider) {
- self::$registeredProviders = array_filter(
- self::$registeredProviders,
+ public function removeProvider($provider) {
+ $this->registeredProviders = array_filter(
+ $this->registeredProviders,
function ($element) use ($provider) {
return ($element['class'] != $provider);
}
);
// force regeneration of providers on next search
- self::$providers=array();
+ $this->providers=array();
}
/**
@@ -74,21 +75,21 @@ class Search {
* @param string $class class name of a OC\Search\Provider
* @param array $options optional
*/
- public static function registerProvider($class, $options=array()) {
- self::$registeredProviders[]=array('class'=>$class, 'options'=>$options);
+ public function registerProvider($class, $options=array()) {
+ $this->registeredProviders[]=array('class'=>$class, 'options'=>$options);
}
/**
* Create instances of all the registered search providers
*/
- private static function initProviders() {
- if(count(self::$providers)>0) {
+ private function initProviders() {
+ if(count($this->providers)>0) {
return;
}
- foreach(self::$registeredProviders as $provider) {
- $class=$provider['class'];
- $options=$provider['options'];
- self::$providers[]=new $class($options);
+ foreach($this->registeredProviders as $provider) {
+ $class = $provider['class'];
+ $options = $provider['options'];
+ $this->providers[]=new $class($options);
}
}
diff --git a/lib/private/search/provider/file.php b/lib/private/search/provider/file.php
index daf73cf79c2..cbd3a253732 100644
--- a/lib/private/search/provider/file.php
+++ b/lib/private/search/provider/file.php
@@ -23,12 +23,12 @@ use OC\Files\Filesystem;
/**
* Provide search results from the 'files' app
*/
-class File extends \OC\Search\Provider {
+class File extends \OCP\Search\Provider {
/**
* Search for files and folders matching the given query
* @param string $query
- * @return \OC\Search\Result
+ * @return \OCP\Search\Result
*/
function search($query) {
$files = Filesystem::search($query);
diff --git a/lib/private/search/result/file.php b/lib/private/search/result/file.php
index 32a4aebc700..da5fa64ef45 100644
--- a/lib/private/search/result/file.php
+++ b/lib/private/search/result/file.php
@@ -22,7 +22,7 @@ use \OC\Files\Filesystem;
/**
* A found file
*/
-class File extends \OC\Search\Result {
+class File extends \OCP\Search\Result {
/**
* Type name; translated in templates
diff --git a/lib/private/server.php b/lib/private/server.php
index 47bdee4b0f8..da705863078 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -186,6 +186,9 @@ class Server extends SimpleContainer implements IServerContainer {
}
return $router;
});
+ $this->registerService('Search', function($c){
+ return new Search();
+ });
$this->registerService('Db', function($c){
return new Db();
});
@@ -422,6 +425,13 @@ class Server extends SimpleContainer implements IServerContainer {
return $this->query('Router');
}
+ /**
+ * Returns a search instance
+ * @return \OCP\ISearch
+ */
+ function getSearch() {
+ return $this->query('Search');
+ }
/**
* Returns an instance of the db facade
diff --git a/lib/public/isearch.php b/lib/public/isearch.php
new file mode 100644
index 00000000000..3b83dbf35e8
--- /dev/null
+++ b/lib/public/isearch.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * ownCloud - App Framework
+ *
+ * @author Jörn Dreyer
+ * @copyright 2014 Jörn Dreyer jfd@owncloud.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCP;
+
+
+/**
+ * Small Interface for Search
+ */
+interface ISearch {
+
+ /**
+ * Search all providers for $query
+ * @param string $query
+ * @return array An array of OCP\Search\Result's
+ */
+ public function search($query);
+
+ /**
+ * Register a new search provider to search with
+ * @param string $class class name of a OCP\Search\Provider
+ * @param array $options optional
+ */
+ public function registerProvider($class, $options = array());
+
+ /**
+ * Remove one existing search provider
+ * @param string $provider class name of a OCP\Search\Provider
+ */
+ public function removeProvider($provider);
+
+ /**
+ * Remove all registered search providers
+ */
+ public function clearProviders();
+
+}
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index 22176c36b8a..8bf97828581 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -204,4 +204,12 @@ interface IServerContainer {
* @return \OCP\Route\IRouter
*/
function getRouter();
+
+ /**
+ * Returns a search instance
+ *
+ * @return \OCP\ISearch
+ */
+ function getSearch();
+
}
diff --git a/lib/private/search/provider.php b/lib/public/search/provider.php
index 45d9f823c55..0506f091dd9 100644
--- a/lib/private/search/provider.php
+++ b/lib/public/search/provider.php
@@ -17,7 +17,7 @@
*
*/
-namespace OC\Search;
+namespace OCP\Search;
/**
* Provides a template for search functionality throughout ownCloud;
@@ -41,7 +41,7 @@ abstract class Provider {
/**
* Search for $query
* @param string $query
- * @return array An array of OC\Search\Result's
+ * @return array An array of OCP\Search\Result's
*/
abstract public function search($query);
}
diff --git a/lib/private/search/result.php b/lib/public/search/result.php
index d228f833810..c70f1bde880 100644
--- a/lib/private/search/result.php
+++ b/lib/public/search/result.php
@@ -17,7 +17,7 @@
*
*/
-namespace OC\Search;
+namespace OCP\Search;
/**
* The generic result of a search