diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php index f1c2d39f240d0a4f59d0f1f0153f9f60d2d56901..d5aacef3e2450e0150667b0fae6200556e8fb4f2 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php +++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php @@ -46,20 +46,10 @@ class AbstractRecord extends AbstractBase protected $defaultTab = 'Holdings'; protected $account; protected $searchClassId = 'Solr'; - protected $searchObject; protected $useResultScroller = true; protected $logStatistics = true; protected $driver = null; - /** - * Constructor - */ - public function __construct() - { - // Set up search class ID-related settings: - $this->searchObject = 'VuFind\Search\\' . $this->searchClassId . '\Results'; - } - /** * Create a new ViewModel. * @@ -217,7 +207,7 @@ class AbstractRecord extends AbstractBase $driver->saveToFavorites($this->getRequest()->getPost()->toArray(), $user); // Grab the followup namespace so we know where to send the user next: - $followup = new SessionContainer($this->searchObject . 'SaveFollowup'); + $followup = new SessionContainer($this->searchClassId . 'SaveFollowup'); $url = isset($followup->url) ? (string)$followup->url : false; if (!empty($url)) { // Display a success status message: @@ -257,7 +247,7 @@ class AbstractRecord extends AbstractBase // ProcessSave action (to get back to where we came from after saving). // We only save if we don't already have a saved URL; otherwise we // might accidentally redirect to the "create new list" screen! - $followup = new SessionContainer($this->searchObject . 'SaveFollowup'); + $followup = new SessionContainer($this->searchClassId . 'SaveFollowup'); $followup->url = (isset($followup->url) && !empty($followup->url)) ? $followup->url : $this->getRequest()->getServer()->get('HTTP_REFERER'); @@ -460,8 +450,9 @@ class AbstractRecord extends AbstractBase // common scenario) and the GET parameters (a fallback used by some // legacy routes). if (!is_object($this->driver)) { - $this->driver = call_user_func( - array($this->searchObject, 'getRecord'), + $sm = $this->getServiceLocator()->get('SearchManager'); + $results = $sm->setSearchClassId($this->searchClassId)->getResults(); + $this->driver = $results->getRecord( $this->params()->fromRoute('id', $this->params()->fromQuery('id')) ); } diff --git a/module/VuFind/src/VuFind/Controller/AuthorityController.php b/module/VuFind/src/VuFind/Controller/AuthorityController.php index 8122d61273351900c989e3ac44734c1e9e1d8e1a..c81e4fef2b49f840dc8135e5c9376d5200691681 100644 --- a/module/VuFind/src/VuFind/Controller/AuthorityController.php +++ b/module/VuFind/src/VuFind/Controller/AuthorityController.php @@ -26,7 +26,6 @@ * @link http://vufind.org Main Site */ namespace VuFind\Controller; -use VuFind\Search\SolrAuth\Results; /** * Authority Controller @@ -69,7 +68,8 @@ class AuthorityController extends AbstractSearch { return $this->createViewModel( array( - 'driver' => Results::getRecord($this->params()->fromQuery('id')) + 'driver' => $this->getSearchManager()->setSearchClassId('SolrAuth') + ->getResults()->getRecord($this->params()->fromQuery('id')) ) ); } diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 004e39ed3b88a5fd40ab7522a63e0a9cded3d1cc..ff7779acd4e55dbd439cb22c9614ccdf5d5b4705 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -34,8 +34,7 @@ use VuFind\Config\Reader as ConfigReader, VuFind\Exception\Auth as AuthException, VuFind\Exception\ListPermission as ListPermissionException, VuFind\Exception\RecordMissing as RecordMissingException, - VuFind\Record\Loader as RecordLoader, - VuFind\Record\Router as RecordRouter, VuFind\Search\Solr\Results as SolrResults, + VuFind\Record\Loader as RecordLoader, VuFind\Record\Router as RecordRouter, Zend\Stdlib\Parameters; /** @@ -730,7 +729,8 @@ class MyResearchController extends AbstractBase if (!isset($current['id'])) { throw new RecordMissingException(); } - $record = SolrResults::getRecord($current['id']); + $record = $this->getSearchManager()->setSearchClassId('Solr') + ->getResults()->getRecord($current['id']); } catch (RecordMissingException $e) { $record = new \VuFind\RecordDriver\Missing(); $record->setRawData( @@ -868,7 +868,8 @@ class MyResearchController extends AbstractBase if (!isset($row['id']) || empty($row['id'])) { throw new \Exception(); } - $record = SolrResults::getRecord($row['id']); + $record = $this->getSearchManager()->setSearchClassId('Solr') + ->getResults()->getRecord($row['id']); $row['title'] = $record->getShortTitle(); } catch (\Exception $e) { if (!isset($row['title'])) { diff --git a/module/VuFind/src/VuFind/Controller/VudlController.php b/module/VuFind/src/VuFind/Controller/VudlController.php index 40e351933255f6d723eedae3d240d850f8db1343..744996e56648855de43e9e8d45cb8d41c115cd52 100644 --- a/module/VuFind/src/VuFind/Controller/VudlController.php +++ b/module/VuFind/src/VuFind/Controller/VudlController.php @@ -57,7 +57,8 @@ class VudlController extends AbstractBase $view->id = $id; // GET XML FILE NAME - $driver = SolrResults::getRecord($id); + $driver = $this->getSearchManager()->setSearchClassId('Solr') + ->getResults()->getRecord($id); if (!method_exists($driver, 'getFullRecord')) { throw new \Exception('Cannot obtain VuDL record'); } diff --git a/module/VuFind/src/VuFind/ILS/Driver/NoILS.php b/module/VuFind/src/VuFind/ILS/Driver/NoILS.php index 0df0eaabe504ab2cafb0fb20883bf7420bc7180c..b9bd25b67911dc4d11e6e0b3ab2a7edb6289d0bc 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/NoILS.php +++ b/module/VuFind/src/VuFind/ILS/Driver/NoILS.php @@ -28,7 +28,8 @@ */ namespace VuFind\ILS\Driver; use VuFind\Config\Reader as ConfigReader, VuFind\Exception\ILS as ILSException, - VuFind\Search\Solr\Results as SolrResults, VuFind\Translator\Translator; + VuFind\Translator\Translator, Zend\ServiceManager\ServiceLocatorAwareInterface, + Zend\ServiceManager\ServiceLocatorInterface; /** * Driver for offline/missing ILS. @@ -40,7 +41,7 @@ use VuFind\Config\Reader as ConfigReader, VuFind\Exception\ILS as ILSException, * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_an_ils_driver Wiki */ -class NoILS extends AbstractBase +class NoILS extends AbstractBase implements ServiceLocatorAwareInterface { /** * Initialize the driver. @@ -69,6 +70,19 @@ class NoILS extends AbstractBase return isset($this->config[$function]) ? $this->config[$function] : false; } + /** + * Get a Solr record. + * + * @param string $id ID of record to retrieve + * + * @return \VuFind\RecordDriver\AbstractBase + */ + public function getSolrRecord($id) + { + return $this->getServiceLocator()->getServiceLocator()->get('SearchManager') + ->setSearchClassId('Solr')->getResults()->getRecord($id); + } + /** * Get Status * @@ -106,7 +120,7 @@ class NoILS extends AbstractBase ); } else if ($useStatus == "marc") { // Retrieve record from index: - $recordDriver = SolrResults::getRecord($id); + $recordDriver = $this->getSolrRecord($id); return $this->getFormattedMarcDetails($recordDriver, 'MarcStatus'); } return array(); @@ -185,7 +199,7 @@ class NoILS extends AbstractBase ); } elseif ($useHoldings == "marc") { // Retrieve record from index: - $recordDriver = SolrResults::getRecord($id); + $recordDriver = $this->getSolrRecord($id); return $this->getFormattedMarcDetails($recordDriver, 'MarcHoldings'); } @@ -316,4 +330,27 @@ class NoILS extends AbstractBase // Block authentication: return null; } + + /** + * Set the service locator. + * + * @param ServiceLocatorInterface $serviceLocator Locator to register + * + * @return NoILS + */ + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + return $this; + } + + /** + * Get the service locator. + * + * @return \Zend\ServiceManager\ServiceLocatorInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } } diff --git a/module/VuFind/src/VuFind/ILS/Driver/Symphony.php b/module/VuFind/src/VuFind/ILS/Driver/Symphony.php index 50c1af041eaea10a7e2bfeba86c5f2188359498c..86473511789f557062a712dfe10707479d303106 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Symphony.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Symphony.php @@ -28,7 +28,9 @@ */ namespace VuFind\ILS\Driver; use SoapClient, SoapFault, VuFind\Cache\Manager as CacheManager, - VuFind\Config\Reader as ConfigReader, VuFind\Exception\ILS as ILSException; + VuFind\Config\Reader as ConfigReader, VuFind\Exception\ILS as ILSException, + Zend\ServiceManager\ServiceLocatorAwareInterface, + Zend\ServiceManager\ServiceLocatorInterface; /** * Symphony Web Services (symws) ILS Driver @@ -41,7 +43,7 @@ use SoapClient, SoapFault, VuFind\Cache\Manager as CacheManager, * @link http://vufind.org/wiki/building_an_ils_driver Wiki */ -class Symphony extends AbstractBase +class Symphony extends AbstractBase implements ServiceLocatorAwareInterface { protected $policyCache = false; protected $policies; @@ -301,7 +303,10 @@ class Symphony extends AbstractBase $entryNumber = $this->config['999Holdings']['entry_number']; - foreach (\VuFind\Search\Solr\Results::getRecords($ids) as $record) { + $records = $this->getServiceLocator()->getServiceLocator() + ->get('SearchManager')->setSearchClassId('Solr')->getResults() + ->getRecords($ids); + foreach ($records as $record) { $results = $record->getFormattedMarcDetails($entryNumber, $marcMap); foreach ($results as $result) { $library = $this->translatePolicyID('LIBR', $result['library']); @@ -1480,4 +1485,27 @@ class Symphony extends AbstractBase return $libraries[0]['locationID']; } } + + /** + * Set the service locator. + * + * @param ServiceLocatorInterface $serviceLocator Locator to register + * + * @return Symphony + */ + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + return $this; + } + + /** + * Get the service locator. + * + * @return \Zend\ServiceManager\ServiceLocatorInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } } diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index 1845be2367b06ba67d4212e6239f6c20088b81b0..970086c0c0f38e4a4288903d5e64791a96895e17 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -687,9 +687,9 @@ class Server // Strip the ID prefix, if necessary: $id = $this->stripID($id); if ($id !== false) { - $resultsClass = 'VuFind\Search\\' . $this->searchClassId . '\Results'; try { - return $resultsClass::getRecord($id); + return $this->searchManager->setSearchClassId($this->searchClassId) + ->getResults()->getRecord($id); } catch (RecordMissingException $e) { return false; } diff --git a/module/VuFind/src/VuFind/Record/Loader.php b/module/VuFind/src/VuFind/Record/Loader.php index a281fda23e5d4d9d2d35a8c85899a5531c0feca8..2f31d6072b72955fdf048716dc42a239a9320763 100644 --- a/module/VuFind/src/VuFind/Record/Loader.php +++ b/module/VuFind/src/VuFind/Record/Loader.php @@ -56,25 +56,24 @@ class Loader implements ServiceLocatorAwareInterface } /** - * Given a record source, return the search class that can load that type of + * Given a record source, return the search object that can load that type of * record. * * @param string $source Record source * * @throws \Exception - * @return string + * @return \VuFind\Search\Base\Results */ protected function getClassForSource($source) { $sm = $this->getServiceLocator()->get('SearchManager'); - $class = $sm->setSearchClassId($source)->getResultsClass(); // Throw an error if we can't find a loader class: - if (!class_exists($class)) { + try { + return $sm->setSearchClassId($source)->getResults(); + } catch (\Exception $e) { throw new \Exception('Unrecognized data source: ' . $source); } - - return $class; } /** @@ -89,8 +88,7 @@ class Loader implements ServiceLocatorAwareInterface public function load($id, $source = 'VuFind') { // Load the record: - $class = $this->getClassForSource($source); - return call_user_func(array($class, 'getRecord'), $id); + return $this->getClassForSource($source)->getRecord($id); } /** @@ -127,9 +125,8 @@ class Loader implements ServiceLocatorAwareInterface // Retrieve the records and put them back in order: $retVal = array(); foreach ($idBySource as $source => $details) { - $class = $this->getClassForSource($source); - $records - = call_user_func(array($class, 'getRecords'), array_keys($details)); + $records = $this->getClassForSource($source) + ->getRecords(array_keys($details)); foreach ($records as $current) { $id = $current->getUniqueId(); $retVal[$details[$id]] = $current; diff --git a/module/VuFind/src/VuFind/Search/Base/Results.php b/module/VuFind/src/VuFind/Search/Base/Results.php index 2c57073ee562619285429e4b36f8374cabb99b59..7c1427a23cdbc6534660bb6a6bb40f79f650f0e8 100644 --- a/module/VuFind/src/VuFind/Search/Base/Results.php +++ b/module/VuFind/src/VuFind/Search/Base/Results.php @@ -184,26 +184,26 @@ abstract class Results implements ServiceLocatorAwareInterface abstract protected function performSearch(); /** - * Static method to retrieve a record by ID. Returns a record driver object. + * Method to retrieve a record by ID. Returns a record driver object. * * @param string $id Unique identifier of record * * @return \VuFind\RecordDriver\AbstractBase */ - public static function getRecord($id) + public function getRecord($id) { // This needs to be defined in subclasses: throw new \Exception('getRecord needs to be defined.'); } /** - * Static method to retrieve an array of records by ID. + * Method to retrieve an array of records by ID. * * @param array $ids Array of unique record identifiers. * * @return array */ - public static function getRecords($ids) + public function getRecords($ids) { // This is the default, dumb behavior for retrieving multiple records -- // just call getRecord() repeatedly. For efficiency, this method should @@ -211,7 +211,7 @@ abstract class Results implements ServiceLocatorAwareInterface $retVal = array(); foreach ($ids as $id) { try { - $retVal[] = static::getRecord($id); + $retVal[] = $this->getRecord($id); } catch (\Exception $e) { // Just omit missing records from the return array; calling code in // \VuFind\Record\Loader::loadBatch() will deal with this. diff --git a/module/VuFind/src/VuFind/Search/EmptySet/Results.php b/module/VuFind/src/VuFind/Search/EmptySet/Results.php index bdd0290f7396f5a40fce862489e9a8b72b0ab423..ac39d259255f965a0cb7220507204589d41b47f4 100644 --- a/module/VuFind/src/VuFind/Search/EmptySet/Results.php +++ b/module/VuFind/src/VuFind/Search/EmptySet/Results.php @@ -65,14 +65,14 @@ class Results extends BaseResults } /** - * Static method to retrieve a record by ID. Returns a record driver object. + * Method to retrieve a record by ID. Returns a record driver object. * * @param string $id Unique identifier of record * * @throws \Exception * @return \VuFind\RecordDriver\AbstractBase */ - public static function getRecord($id) + public function getRecord($id) { throw new \Exception('Cannot get record from empty set.'); } diff --git a/module/VuFind/src/VuFind/Search/Favorites/Results.php b/module/VuFind/src/VuFind/Search/Favorites/Results.php index 2d6271eb950264530bc9cdadb4c5a43e63d00a49..d9f248bca8f1e48b285d294dd7700de86be45266 100644 --- a/module/VuFind/src/VuFind/Search/Favorites/Results.php +++ b/module/VuFind/src/VuFind/Search/Favorites/Results.php @@ -176,13 +176,13 @@ class Results extends BaseResults } /** - * Static method to retrieve a record by ID. Returns a record driver object. + * Method to retrieve a record by ID. Returns a record driver object. * * @param string $id Unique identifier of record * * @return \VuFind\RecordDriver\Base */ - public static function getRecord($id) + public function getRecord($id) { throw new \Exception( 'getRecord not supported by VuFind\Search\Favorites\Results' diff --git a/module/VuFind/src/VuFind/Search/MixedList/Results.php b/module/VuFind/src/VuFind/Search/MixedList/Results.php index 2cc6001a249a722924adcf2cbf1515291ee5161d..0bfbafc168d221d4ae0a37837038368a70639871 100644 --- a/module/VuFind/src/VuFind/Search/MixedList/Results.php +++ b/module/VuFind/src/VuFind/Search/MixedList/Results.php @@ -67,13 +67,13 @@ class Results extends BaseResults } /** - * Static method to retrieve a record by ID. Returns a record driver object. + * Method to retrieve a record by ID. Returns a record driver object. * * @param string $id Unique identifier of record * * @return \VuFind\RecordDriver\Base */ - public static function getRecord($id) + public function getRecord($id) { throw new \Exception( 'getRecord not supported by VuFind\Search\MixedList\Results' diff --git a/module/VuFind/src/VuFind/Search/Solr/Results.php b/module/VuFind/src/VuFind/Search/Solr/Results.php index 189bb36f39a3bd620a0942cd954b151b836dc6a7..3ccb043499628da70cc50ac03d2a12137b247ece 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Results.php +++ b/module/VuFind/src/VuFind/Search/Solr/Results.php @@ -59,9 +59,9 @@ class Results extends BaseResults */ public static function getSolrConnection($shards = null, $index = 'Solr') { - // Turn on all shards by default if none are specified (since we may get - // called in a static context by getRecord(), we need to be sure that any - // given ID will yield results, even if not all shards are on by default). + // Turn on all shards by default if none are specified (we need to be sure + // that any given ID will yield results, even if not all shards are on by + // default). $options = SearchOptions::getInstance($index); $allShards = $options->getShards(); if (is_null($shards)) { @@ -446,14 +446,14 @@ class Results extends BaseResults } /** - * Static method to retrieve a record by ID. Returns a record driver object. + * Method to retrieve a record by ID. Returns a record driver object. * * @param string $id Unique identifier of record * * @throws RecordMissingException * @return \VuFind\RecordDriver\Base */ - public static function getRecord($id) + public function getRecord($id) { $solr = static::getSolrConnection(); @@ -474,13 +474,13 @@ class Results extends BaseResults } /** - * Static method to retrieve an array of records by ID. + * Method to retrieve an array of records by ID. * * @param array $ids Array of unique record identifiers. * * @return array */ - public static function getRecords($ids) + public function getRecords($ids) { // Figure out how many records to retrieve at the same time -- // we'll use either 100 or the ID request limit, whichever is smaller. diff --git a/module/VuFind/src/VuFind/Search/Summon/Results.php b/module/VuFind/src/VuFind/Search/Summon/Results.php index 81eb07ed322f685a58f674eae8a2fd18faed91db..475de19a99663761e5c3be24d74b92180c8b00e5 100644 --- a/module/VuFind/src/VuFind/Search/Summon/Results.php +++ b/module/VuFind/src/VuFind/Search/Summon/Results.php @@ -129,14 +129,14 @@ class Results extends BaseResults } /** - * Static method to retrieve a record by ID. Returns a record driver object. + * Method to retrieve a record by ID. Returns a record driver object. * * @param string $id Unique identifier of record * * @throws RecordMissingException * @return \VuFind\RecordDriver\Base */ - public static function getRecord($id) + public function getRecord($id) { $summon = static::getSummonConnection(); $record = $summon->getRecord($id); diff --git a/module/VuFind/src/VuFind/Search/Tags/Results.php b/module/VuFind/src/VuFind/Search/Tags/Results.php index 09873c0146fee406f9a7d349e3d558054c6b3bc0..a0ce43fbd84b7c74f084d6eac97e298a81edf3cc 100644 --- a/module/VuFind/src/VuFind/Search/Tags/Results.php +++ b/module/VuFind/src/VuFind/Search/Tags/Results.php @@ -78,13 +78,13 @@ class Results extends BaseResults } /** - * Static method to retrieve a record by ID. Returns a record driver object. + * Method to retrieve a record by ID. Returns a record driver object. * * @param string $id Unique identifier of record * * @return \VuFind\RecordDriver\Base */ - public static function getRecord($id) + public function getRecord($id) { throw new \Exception( 'getRecord not supported by VuFind\Search\Tags\Results' diff --git a/module/VuFind/src/VuFind/Search/WorldCat/Results.php b/module/VuFind/src/VuFind/Search/WorldCat/Results.php index eb5e232d6057e82182013f245dc014b55ecd48ec..3bc637c3efce642deb3465b2a89f0cdf6ebd760e 100644 --- a/module/VuFind/src/VuFind/Search/WorldCat/Results.php +++ b/module/VuFind/src/VuFind/Search/WorldCat/Results.php @@ -98,14 +98,14 @@ class Results extends BaseResults } /** - * Static method to retrieve a record by ID. Returns a record driver object. + * Method to retrieve a record by ID. Returns a record driver object. * * @param string $id Unique identifier of record * * @throws RecordMissingException * @return \VuFind\RecordDriver\Base */ - public static function getRecord($id) + public function getRecord($id) { $wc = static::getWorldCatConnection(); $record = $wc->getRecord($id); diff --git a/module/VuFind/tests/RecordDriver/SolrMarcTest.php b/module/VuFind/tests/RecordDriver/SolrMarcTest.php index a2f6a488058456af69d226ad84b77bc5277b6af8..ab165e06be32909dc59586724ee7eeeb056a1084 100644 --- a/module/VuFind/tests/RecordDriver/SolrMarcTest.php +++ b/module/VuFind/tests/RecordDriver/SolrMarcTest.php @@ -48,7 +48,8 @@ class SolrMarcTest extends \VuFind\Tests\TestCase */ public function testBug2() { - $record = \VuFind\Search\Solr\Results::getRecord('testbug2'); + $record = $this->getSearchManager()->setSearchClassId('Solr') + ->getResults()->getRecord('testbug2'); $this->assertEquals( $record->getPrimaryAuthor(), 'Vico, Giambattista, 1668-1744.'