From ef43bc167421f7e694822cdd512c7c70a6e763a0 Mon Sep 17 00:00:00 2001 From: Benjamin Serfhos Date: Mon, 29 Oct 2018 17:22:41 +0100 Subject: [PATCH] [FEATURE] Use interface for SearchService Added cached proxy service for data interaction --- Classes/Controller/SearchController.php | 26 ++++--------- Classes/Domain/Search/CachedSearchService.php | 7 +++- Classes/Domain/Search/SearchService.php | 2 +- .../Domain/Search/SearchServiceInterface.php | 39 +++++++++++++++++++ ext_localconf.php | 4 ++ 5 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 Classes/Domain/Search/SearchServiceInterface.php diff --git a/Classes/Controller/SearchController.php b/Classes/Controller/SearchController.php index 3f12504..8ef0f0c 100644 --- a/Classes/Controller/SearchController.php +++ b/Classes/Controller/SearchController.php @@ -22,7 +22,7 @@ namespace Codappix\SearchCore\Controller; */ use Codappix\SearchCore\Domain\Model\SearchRequest; -use Codappix\SearchCore\Domain\Search\CachedSearchService; +use Codappix\SearchCore\Domain\Search\SearchServiceInterface; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; /** @@ -31,21 +31,24 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; class SearchController extends ActionController { /** - * @var CachedSearchService + * @var SearchServiceInterface */ protected $searchService; /** - * @param CachedSearchService $searchService + * @param SearchServiceInterface $searchService */ - public function __construct(CachedSearchService $searchService) + public function __construct(SearchServiceInterface $searchService) { $this->searchService = $searchService; parent::__construct(); } - public function initializeSearchAction() + /** + * Allow dynamic properties in search request + */ + public function initializeResultsAction() { if (isset($this->settings['searching']['mode']) && $this->settings['searching']['mode'] === 'filter' @@ -63,23 +66,10 @@ class SearchController extends ActionController } } - /** - * Display results and deliver original request and result to view. - */ - public function formAction(SearchRequest $searchRequest = null) - { - $this->action($searchRequest); - } - /** * Display results and deliver original request and result to view. */ public function resultsAction(SearchRequest $searchRequest = null) - { - $this->action($searchRequest); - } - - private function action(SearchRequest $searchRequest = null) { $searchResult = null; if ($searchRequest !== null) { diff --git a/Classes/Domain/Search/CachedSearchService.php b/Classes/Domain/Search/CachedSearchService.php index 48a1614..db94c84 100644 --- a/Classes/Domain/Search/CachedSearchService.php +++ b/Classes/Domain/Search/CachedSearchService.php @@ -29,7 +29,7 @@ use TYPO3\CMS\Core\SingletonInterface; * Service: Cached Search * @package Codappix\SearchCore\Domain\Search */ -class CachedSearchService implements SingletonInterface +class CachedSearchService implements SingletonInterface, SearchServiceInterface { /** * @var array @@ -55,6 +55,11 @@ class CachedSearchService implements SingletonInterface return $this->results[$hash] = $this->searchService->search($searchRequest); } + public function processResult(SearchResultInterface $searchResult): SearchResultInterface + { + return $this->searchService->processResult($searchResult); + } + protected function getHash(SearchRequestInterface $searchRequest): string { if (is_callable([$searchRequest, 'getRequestHash'])) { diff --git a/Classes/Domain/Search/SearchService.php b/Classes/Domain/Search/SearchService.php index 01c6f1b..fedf09e 100644 --- a/Classes/Domain/Search/SearchService.php +++ b/Classes/Domain/Search/SearchService.php @@ -35,7 +35,7 @@ use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; /** * Service to process a search request. */ -class SearchService +class SearchService implements SearchServiceInterface { /** * @var ConnectionInterface diff --git a/Classes/Domain/Search/SearchServiceInterface.php b/Classes/Domain/Search/SearchServiceInterface.php new file mode 100644 index 0000000..fafb06b --- /dev/null +++ b/Classes/Domain/Search/SearchServiceInterface.php @@ -0,0 +1,39 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Codappix\SearchCore\Connection\SearchRequestInterface; +use Codappix\SearchCore\Connection\SearchResultInterface; + +/** + * Service to process a search request. + */ +interface SearchServiceInterface +{ + + public function search(SearchRequestInterface $searchRequest): SearchResultInterface; + + /** + * Processes the result, e.g. applies configured data processing to result. + */ + public function processResult(SearchResultInterface $searchResult): SearchResultInterface; +} diff --git a/ext_localconf.php b/ext_localconf.php index 8452ac8..ef4accd 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -62,5 +62,9 @@ call_user_func(function ($extension, $configuration) { \Codappix\SearchCore\Connection\ConnectionInterface::class, \Codappix\SearchCore\Connection\Elasticsearch::class ); + $container->registerImplementation( + \Codappix\SearchCore\Domain\Search\SearchServiceInterface::class, + \Codappix\SearchCore\Domain\Search\CachedSearchService::class + ); } }, $_EXTKEY, $_EXTCONF);