diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 89e6be48e0abb7c0616fd4effe921b8553cdc05b..86353a6fc170868ba6ad041b31c71fee588e51b7 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -187,6 +187,19 @@ $config = array( 'worldcatterms' => 'VuFind\Recommend\WorldCatTerms', ), ), + 'recorddriver_plugin_manager' => array( + 'abstract_factories' => array('VuFind\RecordDriver\PluginFactory'), + 'invokables' => array( + 'missing' => 'VuFind\RecordDriver\Missing', + 'solrauth' => 'VuFind\RecordDriver\SolrAuth', + 'solrdefault' => 'VuFind\RecordDriver\SolrDefault', + 'solrmarc' => 'VuFind\RecordDriver\SolrMarc', + 'solrreserves' => 'VuFind\RecordDriver\SolrReserves', + 'solrvudl' => 'VuFind\RecordDriver\SolrVudl', + 'summon' => 'VuFind\RecordDriver\Summon', + 'worldcat' => 'VuFind\RecordDriver\WorldCat', + ), + ), 'search_manager' => array( 'default_namespace' => 'VuFind\Search', 'namespaces_by_id' => array( diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index a913c73d2a5398d7af0e04231b67d67abeb82c00..fa72423dbe5ceb79e23f99f43b9ec3cb66809a72 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -91,7 +91,8 @@ class Bootstrap // Use naming conventions to set up a bunch of services based on namespace: $namespaces = array( - 'Auth', 'Autocomplete', 'ILS\Driver', 'Recommend', 'Session' + 'Auth', 'Autocomplete', 'ILS\Driver', 'Recommend', 'RecordDriver', + 'Session' ); foreach ($namespaces as $ns) { $serviceName = str_replace('\\', '', $ns) . 'PluginManager'; diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index ff7779acd4e55dbd439cb22c9614ccdf5d5b4705..538d8a37948e9aec881e4bf478524d6aca195a18 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -732,7 +732,8 @@ class MyResearchController extends AbstractBase $record = $this->getSearchManager()->setSearchClassId('Solr') ->getResults()->getRecord($current['id']); } catch (RecordMissingException $e) { - $record = new \VuFind\RecordDriver\Missing(); + $factory = $this->getServiceLocator()->get('RecordDriverPluginManager'); + $record = clone($factory->get('Missing')); $record->setRawData( array('id' => isset($current['id']) ? $current['id'] : null) ); diff --git a/module/VuFind/src/VuFind/Record/Loader.php b/module/VuFind/src/VuFind/Record/Loader.php index 2f31d6072b72955fdf048716dc42a239a9320763..d945607bb3bb60da3ee1d5281952470cce6b6a16 100644 --- a/module/VuFind/src/VuFind/Record/Loader.php +++ b/module/VuFind/src/VuFind/Record/Loader.php @@ -140,7 +140,9 @@ class Loader implements ServiceLocatorAwareInterface $fields = isset($details['extra_fields']) ? $details['extra_fields'] : array(); $fields['id'] = $details['id']; - $retVal[$i] = new \VuFind\RecordDriver\Missing(); + $factory = $this->getServiceLocator() + ->get('RecordDriverPluginManager'); + $retVal[$i] = clone($factory->get('Missing')); $retVal[$i]->setRawData($fields); } } diff --git a/module/VuFind/src/VuFind/RecordDriver/PluginFactory.php b/module/VuFind/src/VuFind/RecordDriver/PluginFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..a53f12045bfe0b543adbd79bdf656d7dab392152 --- /dev/null +++ b/module/VuFind/src/VuFind/RecordDriver/PluginFactory.php @@ -0,0 +1,48 @@ +<?php +/** + * Record driver plugin factory + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package RecordDrivers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/creating_a_session_handler Wiki + */ +namespace VuFind\RecordDriver; + +/** + * Record driver plugin factory + * + * @category VuFind2 + * @package RecordDrivers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/creating_a_session_handler Wiki + */ +class PluginFactory extends \VuFind\ServiceManager\AbstractPluginFactory +{ + /** + * Constructor + */ + public function __construct() + { + $this->defaultNamespace = 'VuFind\RecordDriver'; + } +} \ No newline at end of file diff --git a/module/VuFind/src/VuFind/RecordDriver/PluginManager.php b/module/VuFind/src/VuFind/RecordDriver/PluginManager.php new file mode 100644 index 0000000000000000000000000000000000000000..6c61443e1c0952373b45d967523be2f13185f7e7 --- /dev/null +++ b/module/VuFind/src/VuFind/RecordDriver/PluginManager.php @@ -0,0 +1,51 @@ +<?php +/** + * Record driver plugin manager + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package RecordDrivers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/creating_a_session_handler Wiki + */ +namespace VuFind\RecordDriver; + +/** + * Record driver plugin manager + * + * @category VuFind2 + * @package RecordDrivers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/creating_a_session_handler Wiki + */ +class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager +{ + /** + * Return the name of the base class or interface that plug-ins must conform + * to. + * + * @return string + */ + protected function getExpectedInterface() + { + return 'VuFind\RecordDriver\AbstractBase'; + } +} \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Search/Solr/Results.php b/module/VuFind/src/VuFind/Search/Solr/Results.php index 140275657b11d3fa1f596bbecd0a850e6b856a95..21d060797f1e75cadca27a84d8ce74e5b1935515 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Results.php +++ b/module/VuFind/src/VuFind/Search/Solr/Results.php @@ -484,7 +484,8 @@ class Results extends BaseResults { // Figure out how many records to retrieve at the same time -- // we'll use either 100 or the ID request limit, whichever is smaller. - $params = new Params(); + $sm = $this->getServiceLocator()->get('SearchManager'); + $params = $sm->setSearchClassId('Solr')->getParams(); $pageSize = $params->getQueryIDLimit(); if ($pageSize < 1 || $pageSize > 100) { $pageSize = 100; @@ -496,7 +497,7 @@ class Results extends BaseResults $currentPage = array_splice($ids, 0, $pageSize, array()); $params->setQueryIDs($currentPage); $params->setLimit($pageSize); - $results = new Results($params); + $results = $sm->setSearchClassId('Solr')->getResults($params); $retVal = array_merge($retVal, $results->getResults()); } @@ -536,26 +537,15 @@ class Results extends BaseResults */ protected function initRecordDriver($data) { - // Remember bad classes to prevent unnecessary file accesses. - static $badClasses = array(); + $factory = $this->getServiceLocator()->get('RecordDriverPluginManager'); - // Determine driver path based on record type: - $driver = 'VuFind\RecordDriver\Solr' . ucwords($data['recordtype']); - - // If we can't load the driver, fall back to the default, index-based one: - if (isset($badClasses[$driver]) || !@class_exists($driver)) { - $badClasses[$driver] = 1; - $driver = 'VuFind\RecordDriver\SolrDefault'; - } + $key = 'Solr' . ucwords($data['recordtype']); + $recordType = $factory->has($key) ? $key : 'SolrDefault'; // Build the object: - if (class_exists($driver)) { - $obj = new $driver(); - $obj->setRawData($data); - return $obj; - } - - throw new \Exception('Cannot find record driver -- ' . $driver); + $driver = clone($factory->get($recordType)); + $driver->setRawData($data); + return $driver; } /** diff --git a/module/VuFind/src/VuFind/Search/SolrAuth/Results.php b/module/VuFind/src/VuFind/Search/SolrAuth/Results.php index 9a3c5bad9af9ff4e31f92b6a43fe3d2371133300..37f4554d914df8c1e1db449f00b2620fefb7355e 100644 --- a/module/VuFind/src/VuFind/Search/SolrAuth/Results.php +++ b/module/VuFind/src/VuFind/Search/SolrAuth/Results.php @@ -76,7 +76,8 @@ class Results extends SolrResults */ protected function initRecordDriver($data) { - $driver = new \VuFind\RecordDriver\SolrAuth(); + $factory = $this->getServiceLocator()->get('RecordDriverPluginManager'); + $driver = clone($factory->get('SolrAuth')); $driver->setRawData($data); return $driver; } diff --git a/module/VuFind/src/VuFind/Search/SolrReserves/Results.php b/module/VuFind/src/VuFind/Search/SolrReserves/Results.php index b84b487999b62458dde1733f6b2bb61c5c719f0d..104bcef35dd49ac3d70ec5fa987b6223a2cd4ddc 100644 --- a/module/VuFind/src/VuFind/Search/SolrReserves/Results.php +++ b/module/VuFind/src/VuFind/Search/SolrReserves/Results.php @@ -65,7 +65,8 @@ class Results extends \VuFind\Search\Solr\Results */ protected function initRecordDriver($data) { - $driver = new \VuFind\RecordDriver\SolrReserves(); + $factory = $this->getServiceLocator()->get('RecordDriverPluginManager'); + $driver = clone($factory->get('SolrReserves')); $driver->setRawData($data); return $driver; } diff --git a/module/VuFind/src/VuFind/Search/Summon/Results.php b/module/VuFind/src/VuFind/Search/Summon/Results.php index 50c2968f877e81eaeb6611b4e6d79706ea0eaa5b..b1637af95349ad3ec3ea8a2841cf08b7d98139fe 100644 --- a/module/VuFind/src/VuFind/Search/Summon/Results.php +++ b/module/VuFind/src/VuFind/Search/Summon/Results.php @@ -158,7 +158,8 @@ class Results extends BaseResults */ protected function initRecordDriver($data) { - $driver = new \VuFind\RecordDriver\Summon(); + $factory = $this->getServiceLocator()->get('RecordDriverPluginManager'); + $driver = clone($factory->get('Summon')); $driver->setRawData($data); return $driver; } diff --git a/module/VuFind/src/VuFind/Search/WorldCat/Results.php b/module/VuFind/src/VuFind/Search/WorldCat/Results.php index c1f1d1c8c3de1ff8a7c426694b30f144d3f839c8..9f3bc4e9937be92be2a356f32b00c565062a38c2 100644 --- a/module/VuFind/src/VuFind/Search/WorldCat/Results.php +++ b/module/VuFind/src/VuFind/Search/WorldCat/Results.php @@ -127,7 +127,8 @@ class Results extends BaseResults */ protected function initRecordDriver($data) { - $driver = new \VuFind\RecordDriver\WorldCat(); + $factory = $this->getServiceLocator()->get('RecordDriverPluginManager'); + $driver = clone($factory->get('WorldCat')); $driver->setRawData($data); return $driver; }