From 90d0668607719345835264e5d88d90516a09ceb1 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 10 Oct 2012 12:47:15 -0400 Subject: [PATCH] Use explicit dependency injection for ILS authentication module instead of relying on service locator. --- module/VuFind/config/module.config.php | 8 ++++++- module/VuFind/src/VuFind/Auth/ILS.php | 22 ++++++++++++------- .../VuFind/src/VuFindTest/Unit/TestCase.php | 9 +++++++- .../tests/unit-tests/src/Auth/ILSTest.php | 2 +- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 470ccdd390a..a88ed1a28ba 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -75,9 +75,15 @@ $config = array( ), 'auth_plugin_manager' => array( 'abstract_factories' => array('VuFind\Auth\PluginFactory'), + 'factories' => array( + 'ils' => function ($sm) { + return new \VuFind\Auth\ILS( + $sm->getServiceLocator()->get('ILSConnection') + ); + }, + ), 'invokables' => array( 'database' => 'VuFind\Auth\Database', - 'ils' => 'VuFind\Auth\ILS', 'ldap' => 'VuFind\Auth\LDAP', 'multiauth' => 'VuFind\Auth\MultiAuth', 'shibboleth' => 'VuFind\Auth\Shibboleth', diff --git a/module/VuFind/src/VuFind/Auth/ILS.php b/module/VuFind/src/VuFind/Auth/ILS.php index 4affd198983..79e5dc139b6 100644 --- a/module/VuFind/src/VuFind/Auth/ILS.php +++ b/module/VuFind/src/VuFind/Auth/ILS.php @@ -43,6 +43,16 @@ class ILS extends AbstractBase { protected $catalog = null; + /** + * Set the ILS connection for this object. + * + * @param \VuFind\ILS\Connection $connection ILS connection to set + */ + public function __construct(\VuFind\ILS\Connection $connection) + { + $this->setCatalog($connection); + } + /** * Get the ILS driver associated with this object (or load the default from * the service manager. @@ -51,23 +61,19 @@ class ILS extends AbstractBase */ public function getCatalog() { - if (null === $this->catalog) { - $this->catalog = $this->getServiceLocator()->getServiceLocator() - ->get('ILSConnection'); - } return $this->catalog; } /** - * Set the ILS driver associated with this object. + * Set the ILS connection for this object. * - * @param \VuFind\ILS\Driver\DriverInterface $driver Driver to set + * @param \VuFind\ILS\Connection $connection ILS connection to set * * @return void */ - public function setCatalog(\VuFind\ILS\Driver\DriverInterface $driver) + public function setCatalog(\VuFind\ILS\Connection $connection) { - $this->catalog = $driver; + $this->catalog = $connection; } /** diff --git a/module/VuFind/src/VuFindTest/Unit/TestCase.php b/module/VuFind/src/VuFindTest/Unit/TestCase.php index d533f805ea4..48f64697de8 100644 --- a/module/VuFind/src/VuFindTest/Unit/TestCase.php +++ b/module/VuFind/src/VuFindTest/Unit/TestCase.php @@ -151,7 +151,14 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase new \Zend\ServiceManager\Config( array( 'abstract_factories' => - array('VuFind\Auth\PluginFactory') + array('VuFind\Auth\PluginFactory'), + 'factories' => array( + 'ils' => function ($sm) { + return new \VuFind\Auth\ILS( + new \VuFind\ILS\Connection() + ); + }, + ), ) ) ); diff --git a/module/VuFind/tests/unit-tests/src/Auth/ILSTest.php b/module/VuFind/tests/unit-tests/src/Auth/ILSTest.php index 0f5274b1772..986daf535e7 100644 --- a/module/VuFind/tests/unit-tests/src/Auth/ILSTest.php +++ b/module/VuFind/tests/unit-tests/src/Auth/ILSTest.php @@ -49,7 +49,7 @@ class ILSTest extends \VuFindTest\Unit\DbTestCase { $this->driver = $this->getMock('VuFind\ILS\Driver\Demo'); $this->auth = $this->getAuthManager()->get('ILS'); - $this->auth->setCatalog($this->driver); + $this->auth->getCatalog()->setDriver($this->driver);; } /** -- GitLab