From 8a94f1dbabea9ae9e8b36c246dd3b2f395002a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 14 Mar 2016 17:10:14 +0100 Subject: [PATCH] FEATURE: add registering for new search engines. --- app/Handlers/Contracts/SearchHandler.php | 17 ++++++ .../Contracts/SearchPresenterHandler.php | 14 +++++ .../Registrators/SearchEngineRegistrator.php | 57 +++++++++++++++++++ app/Handlers/Search/Content.php | 36 ++++++++++++ app/Handlers/Search/Presenters/Content.php | 12 ++++ app/Providers/AppServiceProvider.php | 18 ++++++ 6 files changed, 154 insertions(+) create mode 100644 app/Handlers/Contracts/SearchHandler.php create mode 100644 app/Handlers/Contracts/SearchPresenterHandler.php create mode 100644 app/Handlers/Registrators/SearchEngineRegistrator.php create mode 100644 app/Handlers/Search/Content.php create mode 100644 app/Handlers/Search/Presenters/Content.php diff --git a/app/Handlers/Contracts/SearchHandler.php b/app/Handlers/Contracts/SearchHandler.php new file mode 100644 index 00000000..ad4b157e --- /dev/null +++ b/app/Handlers/Contracts/SearchHandler.php @@ -0,0 +1,17 @@ +searchEngines = []; + } + + /** + * Method for registering new settings extensions/parts + * + * @param SearchHandler $search + * @param SearchPresenterHandler $presenter + * + * @throws EnumerationExistsException + */ + public function register(SearchHandler $search, SearchPresenterHandler $presenter) + { + $this->checkIfRegistered($search->getId()); + + // register new extension + $this->searchEngines[$search->getId()] = [$search, $presenter]; + } + + /** + * Getter for all registered extensions + * + * @return array + */ + public function get() + { + return $this->searchEngines; + } + + /** + * Checks if this section is not already defined + * + * @param $id + * + * @throws EnumerationExistsException + */ + private function checkIfRegistered($id) + { + if (isset($this->searchEngines[$id])) { + throw new EnumerationExistsException('Already existing search engine ' . $id); + } + } +} diff --git a/app/Handlers/Search/Content.php b/app/Handlers/Search/Content.php new file mode 100644 index 00000000..eaf0f0c9 --- /dev/null +++ b/app/Handlers/Search/Content.php @@ -0,0 +1,36 @@ +orWhere('description', 'LIKE', $token) + ->orWhere('keywords', 'LIKE', $token) + ->orWhere('title', 'LIKE', $token) + ->orWhere('url', 'LIKE', $token) + ->get(); + } + + public function getId() + { + return 'content'; + } + + public function getName() + { + return trans('...'); + } +} \ No newline at end of file diff --git a/app/Handlers/Search/Presenters/Content.php b/app/Handlers/Search/Presenters/Content.php new file mode 100644 index 00000000..8d0e8342 --- /dev/null +++ b/app/Handlers/Search/Presenters/Content.php @@ -0,0 +1,12 @@ +registerWidgets(); $this->registerTemplates(); $this->registerSettings(); + $this->registerSearch(); } /** @@ -51,6 +55,10 @@ class AppServiceProvider extends ServiceProvider $this->app->singleton('registerSettingsExtension', function ($app) { return new SettingsExtensionRegistrator($app); }); + + $this->app->singleton('registerSearchEngine', function ($app) { + return new SearchEngineRegistrator($app); + }); } /** @@ -91,4 +99,14 @@ class AppServiceProvider extends ServiceProvider $registrator->register('basic', 'admin/settings.basic', 'admin.settings.parts.basic'); $registrator->register('meta', 'admin/settings.meta', 'admin.settings.parts.meta'); } + + /** + * Register callbacks used for searching + */ + private function registerSearch() + { + $registrator = $this->app->make('registerSearchEngine'); + + $registrator->register(new Content(), new ContentPresenter()); + } }