The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 4560c953 authored by Demian Katz's avatar Demian Katz
Browse files

Improve reusability of FacetCache factories.

parent bd11bd04
No related merge requests found
......@@ -39,16 +39,21 @@ use Zend\ServiceManager\Factory\FactoryInterface;
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
abstract class FacetCacheFactory implements FactoryInterface
class FacetCacheFactory implements FactoryInterface
{
/**
* Create a results object with appropriate pre-populated values.
* Create a results object.
*
* @param ContainerInterface $container Service manager
* @param string $name Name of results object to load (based
* on name of FacetCache service name)
*
* @return \VuFind\Search\Base\Results
* @return Results
*/
abstract protected function getResults(ContainerInterface $container);
protected function getResults(ContainerInterface $container, $name)
{
return $container->get('VuFind\Search\Results\PluginManager')->get($name);
}
/**
* Create an object
......@@ -70,7 +75,9 @@ abstract class FacetCacheFactory implements FactoryInterface
if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.');
}
$results = $this->getResults($container);
$parts = explode('\\', $requestedName);
$requestedNamespace = $parts[count($parts) - 2];
$results = $this->getResults($container, $requestedNamespace);
$cacheManager = $container->get('VuFind\Cache\Manager');
$language = $container->get('Zend\Mvc\I18n\Translator')->getLocale();
return new $requestedName($results, $cacheManager, $language);
......
......@@ -55,8 +55,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
*/
protected $factories = [
'VuFind\Search\Solr\FacetCache' => 'VuFind\Search\Solr\FacetCacheFactory',
'VuFind\Search\Summon\FacetCache' =>
'VuFind\Search\Summon\FacetCacheFactory',
'VuFind\Search\Summon\FacetCache' => 'VuFind\Search\Base\FacetCacheFactory',
];
/**
......
......@@ -44,15 +44,17 @@ class FacetCacheFactory extends \VuFind\Search\Base\FacetCacheFactory
* Create a results object with hidden filters pre-populated.
*
* @param ContainerInterface $container Service manager
* @param string $name Name of results object to load (based
* on name of FacetCache service name)
*
* @return \VuFind\Search\Base\Results
*/
protected function getResults(ContainerInterface $container)
protected function getResults(ContainerInterface $container, $name)
{
$filters = $container->get('VuFind\Search\SearchTabsHelper')
->getHiddenFilters('Solr');
->getHiddenFilters($name);
$results = $container->get('VuFind\Search\Results\PluginManager')
->get('Solr');
->get($name);
$params = $results->getParams();
foreach ($filters as $key => $subFilters) {
foreach ($subFilters as $filter) {
......
<?php
/**
* Summon FacetCache Factory.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Search_Summon
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
namespace VuFind\Search\Summon;
use Interop\Container\ContainerInterface;
/**
* Summon FacetCache Factory.
*
* @category VuFind
* @package Search_Summon
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class FacetCacheFactory extends \VuFind\Search\Base\FacetCacheFactory
{
/**
* Create a results object.
*
* @param ContainerInterface $container Service manager
*
* @return \VuFind\Search\Base\Results
*/
protected function getResults(ContainerInterface $container)
{
return $container->get('VuFind\Search\Results\PluginManager')->get('Summon');
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment