From af56124b437cd228ea36b1e8d41b5e06b973f4d8 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 1 Mar 2013 09:11:30 -0500 Subject: [PATCH] Inject configuration into WorldCatUtils. --- module/VuFind/config/module.config.php | 7 ++++- .../src/VuFind/Connection/WorldCatUtils.php | 28 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 8c4bb408ed9..81a40b7e60d 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -270,11 +270,16 @@ $config = array( $sm->get('VuFind\Http')->createClient() ); }, + 'VuFind\WorldCatUtils' => function ($sm) { + $config = $sm->get('VuFind\Config')->get('config'); + $wcId = isset($config->WorldCat->id) + ? $config->WorldCat->id : false; + return new \VuFind\Connection\WorldCatUtils($wcId); + }, ), 'invokables' => array( 'VuFind\RecordLoader' => 'VuFind\Record\Loader', 'VuFind\SessionManager' => 'Zend\Session\SessionManager', - 'VuFind\WorldCatUtils' => 'VuFind\Connection\WorldCatUtils', ), 'initializers' => array( array('VuFind\ServiceManager\Initializer', 'initInstance'), diff --git a/module/VuFind/src/VuFind/Connection/WorldCatUtils.php b/module/VuFind/src/VuFind/Connection/WorldCatUtils.php index a5668984969..a5b600deee7 100644 --- a/module/VuFind/src/VuFind/Connection/WorldCatUtils.php +++ b/module/VuFind/src/VuFind/Connection/WorldCatUtils.php @@ -26,8 +26,7 @@ * @link http://vufind.org/wiki/vufind2:developer_manual Wiki */ namespace VuFind\Connection; -use File_MARCXML, VuFind\Config\Reader as ConfigReader, - VuFind\XSLT\Processor as XSLTProcessor, Zend\Log\LoggerInterface; +use File_MARCXML, VuFind\XSLT\Processor as XSLTProcessor, Zend\Log\LoggerInterface; /** * World Cat Utilities @@ -49,6 +48,23 @@ class WorldCatUtils implements \Zend\Log\LoggerAwareInterface */ protected $logger = false; + /** + * WorldCat ID + * + * @var string + */ + protected $worldCatId; + + /** + * Constructor + * + * @param string $worldcatId WorldCat ID + */ + public function __construct($worldCatId) + { + $this->worldCatId = $worldCatId; + } + /** * Set the logger * @@ -82,13 +98,7 @@ class WorldCatUtils implements \Zend\Log\LoggerAwareInterface */ protected function getWorldCatId() { - static $wcId = null; - if (is_null($wcId)) { - $config = ConfigReader::getConfig(); - $wcId = isset($config->WorldCat->id) - ? $config->WorldCat->id : false; - } - return $wcId; + return $this->worldCatId; } /** -- GitLab