Skip to content
Snippets Groups Projects
Commit 07ea7198 authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Eliminate static content factories.

- Progress on VUFIND-1302.
parent b1c5b010
No related merge requests found
......@@ -27,7 +27,7 @@
*/
namespace VuFind\Content;
use Zend\ServiceManager\ServiceManager;
use Interop\Container\ContainerInterface;
/**
* Factory for instantiating content loaders
......@@ -40,85 +40,64 @@ use Zend\ServiceManager\ServiceManager;
*
* @codeCoverageIgnore
*/
class Factory
class Factory implements \Zend\ServiceManager\Factory\FactoryInterface
{
/**
* Create Author Notes loader
* Get the configuration setting name to get content provider settings.
*
* @param ServiceManager $sm Service manager
* @param string $name Requested service name
*
* @return mixed
* @return string
*/
public static function getAuthorNotes(ServiceManager $sm)
protected function getConfigSettingName($name)
{
$loader = $sm->get('VuFind\Content\AuthorNotes\PluginManager');
$config = $sm->get('VuFind\Config\PluginManager')->get('config');
$providers = isset($config->Content->authorNotes)
? $config->Content->authorNotes : '';
return new Loader($loader, $providers);
// Account for one special exception:
$lcName = strtolower($name);
return $lcName === 'authornotes' ? 'authorNotes' : $lcName;
}
/**
* Create Excerpts loader
* Get the plugin manager service name to build a content provider service.
*
* @param ServiceManager $sm Service manager
* @param string $name Requested service name
*
* @return mixed
* @return string
*/
public static function getExcerpts(ServiceManager $sm)
protected function getPluginManagerServiceName($name)
{
$loader = $sm->get('VuFind\Content\Excerpts\PluginManager');
$config = $sm->get('VuFind\Config\PluginManager')->get('config');
$providers = isset($config->Content->excerpts)
? $config->Content->excerpts : '';
return new Loader($loader, $providers);
$lcName = strtolower($name);
// Account for two special legacy exceptions:
$exceptions = ['authornotes' => 'AuthorNotes', 'toc' => 'TOC'];
$formattedName = $exceptions[$lcName] ?? ucfirst($lcName);
return 'VuFind\Content\\' . $formattedName . '\PluginManager';
}
/**
* Create Reviews loader
* Create an object
*
* @param ServiceManager $sm Service manager
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return mixed
*/
public static function getReviews(ServiceManager $sm)
{
$loader = $sm->get('VuFind\Content\Reviews\PluginManager');
$config = $sm->get('VuFind\Config\PluginManager')->get('config');
$providers = isset($config->Content->reviews)
? $config->Content->reviews : '';
return new Loader($loader, $providers);
}
/**
* Create Summaries loader
* @return object
*
* @param ServiceManager $sm Service manager
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*
* @return mixed
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public static function getSummaries(ServiceManager $sm)
{
$loader = $sm->get('VuFind\Content\Summaries\PluginManager');
$config = $sm->get('VuFind\Config\PluginManager')->get('config');
$providers = isset($config->Content->summaries)
? $config->Content->summaries : '';
return new Loader($loader, $providers);
}
/**
* Create TOC loader
*
* @param ServiceManager $sm Service manager
*
* @return mixed
*/
public static function getTOC(ServiceManager $sm)
{
$loader = $sm->get('VuFind\Content\TOC\PluginManager');
$config = $sm->get('VuFind\Config\PluginManager')->get('config');
$providers = isset($config->Content->toc)
? $config->Content->toc : '';
return new Loader($loader, $providers);
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
$pm = $container->get($this->getPluginManagerServiceName($requestedName));
$config = $container->get('VuFind\Config\PluginManager')->get('config');
$setting = $this->getConfigSettingName($requestedName);
$providers = $config->Content->$setting ?? '';
return new Loader($pm, $providers);
}
}
......@@ -44,11 +44,11 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
* @var array
*/
protected $factories = [
'authornotes' => 'VuFind\Content\Factory::getAuthorNotes',
'excerpts' => 'VuFind\Content\Factory::getExcerpts',
'reviews' => 'VuFind\Content\Factory::getReviews',
'summaries' => 'VuFind\Content\Factory::getSummaries',
'toc' => 'VuFind\Content\Factory::getTOC',
'authornotes' => Factory::class,
'excerpts' => Factory::class,
'reviews' => Factory::class,
'summaries' => Factory::class,
'toc' => Factory::class,
];
/**
......
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