From 1576688929062309355ec6bab3a026008cb0bbba Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 5 Sep 2012 10:25:40 -0400 Subject: [PATCH] Made search params/results service locator aware (not used yet -- refactoring in progress). --- .../VuFind/src/VuFind/Search/Base/Params.php | 53 ++++++++++++++++++- .../VuFind/src/VuFind/Search/Base/Results.php | 45 +++++++++++++++- 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/module/VuFind/src/VuFind/Search/Base/Params.php b/module/VuFind/src/VuFind/Search/Base/Params.php index 948915f4e3f..5d73d9b8a73 100644 --- a/module/VuFind/src/VuFind/Search/Base/Params.php +++ b/module/VuFind/src/VuFind/Search/Base/Params.php @@ -27,7 +27,9 @@ */ namespace VuFind\Search\Base; use VuFind\Config\Reader as ConfigReader, VuFind\Search\Options as SearchOptions, - VuFind\Translator\Translator; + VuFind\Translator\Translator, + Zend\ServiceManager\ServiceLocatorAwareInterface, + Zend\ServiceManager\ServiceLocatorInterface; /** * Abstract parameters search model. @@ -40,7 +42,7 @@ use VuFind\Config\Reader as ConfigReader, VuFind\Search\Options as SearchOptions * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://www.vufind.org Main Page */ -class Params +class Params implements ServiceLocatorAwareInterface { // Search terms protected $searchTerms = array(); @@ -65,6 +67,8 @@ class Params protected $facetConfig = array(); protected $checkboxFacets = array(); protected $filterList = array(); + // Service locator + protected $serviceLocator; /** * Constructor @@ -89,6 +93,11 @@ class Params // If no options have been set, use defaults: if (null === $this->options) { // Create a copy of the default configuration: + /* TODO: change after Search Manager refactoring + $default = $this->getSearchManager() + ->setSearchClassId($this->getSearchClassId())->getOptionsInstance(); + $this->options = clone($default); + */ $this->options = clone( SearchOptions::getInstance($this->getSearchClassId()) ); @@ -127,6 +136,9 @@ class Params */ public function getSearchClassId() { + /* TODO: change this when Search Manager refactoring is done: + return $this->getSearchManager()->extractSearchClassId(get_class($this)); + */ return SearchOptions::extractSearchClassId(get_class($this)); } @@ -1484,4 +1496,41 @@ class Params { return $this->selectedShards; } + + /** + * Set the service locator. + * + * @param ServiceLocatorInterface $serviceLocator Locator to register + * + * @return Manager + */ + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + return $this; + } + + /** + * Get the service locator. + * + * @return \Zend\ServiceManager\ServiceLocatorInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } + + /** + * Pull the search manager from the service locator. + * + * @return \VuFind\Search\Manager + */ + protected function getSearchManager() + { + $sl = $this->getServiceLocator(); + if (!is_object($sl)) { + throw new \Exception('Could not find service locator'); + } + return $sl->get('SearchManager'); + } } \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Search/Base/Results.php b/module/VuFind/src/VuFind/Search/Base/Results.php index 265b23423f9..2378b1982ed 100644 --- a/module/VuFind/src/VuFind/Search/Base/Results.php +++ b/module/VuFind/src/VuFind/Search/Base/Results.php @@ -26,7 +26,9 @@ * @link http://www.vufind.org Main Page */ namespace VuFind\Search\Base; -use VuFind\Search\UrlQueryHelper, Zend\Paginator\Paginator; +use VuFind\Search\UrlQueryHelper, Zend\Paginator\Paginator, + Zend\ServiceManager\ServiceLocatorAwareInterface, + Zend\ServiceManager\ServiceLocatorInterface; /** * Abstract results search model. @@ -39,7 +41,7 @@ use VuFind\Search\UrlQueryHelper, Zend\Paginator\Paginator; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://www.vufind.org Main Page */ -abstract class Results +abstract class Results implements ServiceLocatorAwareInterface { protected $params; // Total number of results available @@ -60,6 +62,8 @@ abstract class Results protected $helpers = array(); // Spelling protected $suggestions = null; + // Service locator + protected $serviceLocator; /** * Constructor @@ -515,4 +519,41 @@ abstract class Results // pull them from the results object. return $this->getParams()->getRecommendations($location); } + + /** + * Set the service locator. + * + * @param ServiceLocatorInterface $serviceLocator Locator to register + * + * @return Manager + */ + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + return $this; + } + + /** + * Get the service locator. + * + * @return \Zend\ServiceManager\ServiceLocatorInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } + + /** + * Pull the search manager from the service locator. + * + * @return \VuFind\Search\Manager + */ + protected function getSearchManager() + { + $sl = $this->getServiceLocator(); + if (!is_object($sl)) { + throw new \Exception('Could not find service locator'); + } + return $sl->get('SearchManager'); + } } \ No newline at end of file -- GitLab