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

Adjust interface of abstract plugin factories.

parent a24b190a
No related merge requests found
......@@ -27,7 +27,7 @@
*/
namespace VuFind\Search\Options;
use Zend\ServiceManager\ServiceLocatorInterface;
use Interop\Container\ContainerInterface;
/**
* Search options plugin factory
......@@ -52,18 +52,20 @@ class PluginFactory extends \VuFind\ServiceManager\AbstractPluginFactory
/**
* Create a service for the specified name.
*
* @param ServiceLocatorInterface $serviceLocator Service locator
* @param string $name Name of service
* @param string $requestedName Unfiltered name of service
* @param ContainerInterface $container Service container
* @param string $requestedName Name of service
* @param array $options Options (unused)
*
* @return object
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator,
$name, $requestedName
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
$class = $this->getClassName($name, $requestedName);
$class = $this->getClassName($requestedName);
return new $class(
$serviceLocator->getServiceLocator()->get('VuFind\Config')
$container->getServiceLocator()->get('VuFind\Config')
);
}
}
......@@ -53,6 +53,6 @@ class Factory
{
$factory = new PluginFactory();
$helper = $sm->getServiceLocator()->get('VuFind\HierarchicalFacetHelper');
return $factory->createServiceWithName($sm, 'solr', 'Solr', [$helper]);
return $factory($sm, 'Solr', [$helper]);
}
}
......@@ -27,7 +27,7 @@
*/
namespace VuFind\Search\Params;
use Zend\ServiceManager\ServiceLocatorInterface;
use Interop\Container\ContainerInterface;
/**
* Search params plugin factory
......@@ -52,22 +52,22 @@ class PluginFactory extends \VuFind\ServiceManager\AbstractPluginFactory
/**
* Create a service for the specified name.
*
* @param ServiceLocatorInterface $serviceLocator Service locator
* @param string $name Name of service
* @param string $requestedName Unfiltered name of service
* @param array $extraParams Extra constructor parameters
* (to follow the Options object and config loader)
* @param ContainerInterface $container Service container
* @param string $requestedName Name of service
* @param array $extras Extra options
*
* @return object
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator,
$name, $requestedName, array $extraParams = []
public function __invoke(ContainerInterface $container, $requestedName,
array $extras = null
) {
$options = $serviceLocator->getServiceLocator()
$options = $container->getServiceLocator()
->get('VuFind\SearchOptionsPluginManager')->get($requestedName);
$class = $this->getClassName($name, $requestedName);
$configLoader = $serviceLocator->getServiceLocator()->get('VuFind\Config');
$class = $this->getClassName($requestedName);
$configLoader = $container->getServiceLocator()->get('VuFind\Config');
// Clone the options instance in case caller modifies it:
return new $class(clone $options, $configLoader, ...$extraParams);
return new $class(clone $options, $configLoader, ...($extras ?: []));
}
}
......@@ -53,8 +53,8 @@ class Factory
{
$factory = new PluginFactory();
$tm = $sm->getServiceLocator()->get('VuFind\DbTablePluginManager');
$obj = $factory->createServiceWithName(
$sm, 'favorites', 'Favorites',
$obj = $factory(
$sm, 'Favorites',
[$tm->get('Resource'), $tm->get('UserList')]
);
$init = new \ZfcRbac\Initializer\AuthorizationServiceInitializer();
......@@ -72,7 +72,7 @@ class Factory
public static function getSolr(ServiceManager $sm)
{
$factory = new PluginFactory();
$solr = $factory->createServiceWithName($sm, 'solr', 'Solr');
$solr = $factory($sm, 'Solr');
$config = $sm->getServiceLocator()
->get('VuFind\Config')->get('config');
$spellConfig = isset($config->Spelling)
......@@ -94,8 +94,6 @@ class Factory
{
$factory = new PluginFactory();
$tm = $sm->getServiceLocator()->get('VuFind\DbTablePluginManager');
return $factory->createServiceWithName(
$sm, 'tags', 'Tags', [$tm->get('Tags')]
);
return $factory($sm, 'Tags', [$tm->get('Tags')]);
}
}
......@@ -27,7 +27,7 @@
*/
namespace VuFind\Search\Results;
use Zend\ServiceManager\ServiceLocatorInterface;
use Interop\Container\ContainerInterface;
/**
* Search results plugin factory
......@@ -52,24 +52,26 @@ class PluginFactory extends \VuFind\ServiceManager\AbstractPluginFactory
/**
* Create a service for the specified name.
*
* @param ServiceLocatorInterface $serviceLocator Service locator
* @param string $name Name of service
* @param string $requestedName Unfiltered name of service
* @param array $extraParams Extra constructor parameters
* (to follow the Params, Search and RecordLoader objects)
* @param ContainerInterface $container Service container
* @param string $requestedName Name of service
* @param array $extras Extra options
*
* @return object
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator,
$name, $requestedName, array $extraParams = []
public function __invoke(ContainerInterface $container, $requestedName,
array $extras = null
) {
$params = $serviceLocator->getServiceLocator()
$params = $container->getServiceLocator()
->get('VuFind\SearchParamsPluginManager')->get($requestedName);
$searchService = $serviceLocator->getServiceLocator()
->get('VuFind\Search');
$recordLoader = $serviceLocator->getServiceLocator()
->get('VuFind\RecordLoader');
$class = $this->getClassName($name, $requestedName);
return new $class($params, $searchService, $recordLoader, ...$extraParams);
$class = $this->getClassName($requestedName);
return new $class(
$params, $searchService, $recordLoader, ...($extras ?: [])
);
}
}
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