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

Modernize WorldCatUtils service.

- Use fully qualified class name as service name.
- Eliminate static factory.
parent 1851baa2
No related merge requests found
......@@ -345,7 +345,7 @@ $config = [
'VuFind\SMS\SMSInterface' => 'VuFind\SMS\Factory',
'VuFind\Solr\Writer' => 'VuFind\Solr\WriterFactory',
'VuFind\Tags' => 'VuFind\TagsFactory',
'VuFind\WorldCatUtils' => 'VuFind\Service\Factory::getWorldCatUtils',
'VuFind\Connection\WorldCatUtils' => 'VuFind\Connection\WorldCatUtilsFactory',
'VuFindHttp\HttpService' => 'VuFind\Service\Factory::getHttp',
'VuFindSearch\Service' => 'VuFind\Service\Factory::getSearchService',
'Zend\Db\Adapter\Adapter' => 'VuFind\Service\Factory::getDbAdapter',
......@@ -413,6 +413,7 @@ $config = [
'VuFind\SessionPluginManager' => 'VuFind\Session\PluginManager',
'VuFind\SMS' => 'VuFind\SMS\SMSInterface',
'VuFind\Translator' => 'Zend\Mvc\I18n\Translator',
'VuFind\WorldCatUtils' => 'VuFind\Connection\WorldCatUtils',
'VuFind\YamlReader' => 'VuFind\Config\YamlReader',
],
],
......
<?php
/**
* WorldCat utils factory.
*
* PHP version 5
*
* 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 WorldCat
* @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\Connection;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/**
* WorldCat utils factory.
*
* @category VuFind
* @package WorldCat
* @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 WorldCatUtilsFactory implements FactoryInterface
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @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
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.');
}
$config = $container->get('VuFind\Config\PluginManager')->get('config');
$client = $container->get('VuFindHttp\HttpService')->createClient();
$ip = $container->get('Request')->getServer()->get('SERVER_ADDR');
return new $requestedName(
isset($config->WorldCat) ? $config->WorldCat : null,
$client, true, $ip
);
}
}
......@@ -342,8 +342,6 @@ class Factory
*/
public static function getWorldCatIdentities(ServiceManager $sm)
{
return new WorldCatIdentities(
$sm->get('VuFind\WorldCatUtils')
);
return new WorldCatIdentities($sm->get('VuFind\Connection\WorldCatUtils'));
}
}
......@@ -165,22 +165,4 @@ class Factory
return $translator;
}
/**
* Construct the WorldCat helper.
*
* @param ServiceManager $sm Service manager.
*
* @return \VuFind\Connection\WorldCatUtils
*/
public static function getWorldCatUtils(ServiceManager $sm)
{
$config = $sm->get('VuFind\Config\PluginManager')->get('config');
$client = $sm->get('VuFindHttp\HttpService')->createClient();
$ip = $sm->get('Request')->getServer()->get('SERVER_ADDR');
return new \VuFind\Connection\WorldCatUtils(
isset($config->WorldCat) ? $config->WorldCat : null,
$client, true, $ip
);
}
}
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