diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 0d574b0958f965f1786622a38d7ae70e6cd34d74..6a6e4e7147b17d00e3fa29dd6fc501fdc2631ba9 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -322,6 +322,7 @@ $config = array( 'abstract_factories' => array('VuFind\Db\Table\PluginFactory'), 'factories' => array( 'resource' => 'VuFind\Db\Table\Factory::getResource', + 'user' => 'VuFind\Db\Table\Factory::getUser', ), 'invokables' => array( 'changetracker' => 'VuFind\Db\Table\ChangeTracker', @@ -331,7 +332,6 @@ $config = array( 'search' => 'VuFind\Db\Table\Search', 'session' => 'VuFind\Db\Table\Session', 'tags' => 'VuFind\Db\Table\Tags', - 'user' => 'VuFind\Db\Table\User', 'userlist' => 'VuFind\Db\Table\UserList', 'userresource' => 'VuFind\Db\Table\UserResource', 'userstats' => 'VuFind\Db\Table\UserStats', diff --git a/module/VuFind/src/VuFind/Db/Row/User.php b/module/VuFind/src/VuFind/Db/Row/User.php index e64d61e36697d642531bfc1b7590e01904d4ccbd..5cfe5fd889b6208450f4cb10e70ff1b140dcde31 100644 --- a/module/VuFind/src/VuFind/Db/Row/User.php +++ b/module/VuFind/src/VuFind/Db/Row/User.php @@ -58,6 +58,13 @@ class User extends ServiceLocatorAwareGateway */ protected $encryptionKey = null; + /** + * VuFind configuration + * + * @var \Zend\Config\Config + */ + protected $config = null; + /** * Constructor * @@ -68,6 +75,18 @@ class User extends ServiceLocatorAwareGateway parent::__construct('id', 'user', $adapter); } + /** + * Configuration setter + * + * @param \Zend\Config\Config $config VuFind configuration + * + * @return void + */ + public function setConfig(\Zend\Config\Config $config) + { + $this->config = $config; + } + /** * Reset ILS login credentials. * @@ -124,11 +143,9 @@ class User extends ServiceLocatorAwareGateway protected function passwordEncryptionEnabled() { if (null === $this->encryptionEnabled) { - $config = $this->getServiceLocator()->getServiceLocator() - ->get('VuFind\Config')->get('config'); $this->encryptionEnabled - = isset($config->Authentication->encrypt_ils_password) - ? $config->Authentication->encrypt_ils_password : false; + = isset($this->config->Authentication->encrypt_ils_password) + ? $this->config->Authentication->encrypt_ils_password : false; } return $this->encryptionEnabled; } @@ -153,16 +170,14 @@ class User extends ServiceLocatorAwareGateway // Load encryption key from configuration if not already present: if (null === $this->encryptionKey) { - $config = $this->getServiceLocator()->getServiceLocator() - ->get('VuFind\Config')->get('config'); - if (!isset($config->Authentication->ils_encryption_key) - || empty($config->Authentication->ils_encryption_key) + if (!isset($this->config->Authentication->ils_encryption_key) + || empty($this->config->Authentication->ils_encryption_key) ) { throw new \VuFind\Exception\PasswordSecurity( 'ILS password encryption on, but no key set.' ); } - $this->encryptionKey = $config->Authentication->ils_encryption_key; + $this->encryptionKey = $this->config->Authentication->ils_encryption_key; } // Perform encryption: diff --git a/module/VuFind/src/VuFind/Db/Table/Factory.php b/module/VuFind/src/VuFind/Db/Table/Factory.php index bc308970714fee04044d1d308a229f351a1e26d3..5497763a6ca5d0165e0c382a29d93d9dbc7bd679 100644 --- a/module/VuFind/src/VuFind/Db/Table/Factory.php +++ b/module/VuFind/src/VuFind/Db/Table/Factory.php @@ -51,4 +51,18 @@ class Factory { return new Resource($sm->getServiceLocator()->get('VuFind\DateConverter')); } + + /** + * Construct the User table. + * + * @param ServiceManager $sm Service manager. + * + * @return User + */ + public static function getUser(ServiceManager $sm) + { + return new User( + $sm->getServiceLocator()->get('VuFind\Config')->get('config') + ); + } } \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Db/Table/Gateway.php b/module/VuFind/src/VuFind/Db/Table/Gateway.php index d1d314c0658432ce2e2181312d81cfa97e1b891b..05b5698241c9c8a4474a83e4d937c6788b409a5a 100644 --- a/module/VuFind/src/VuFind/Db/Table/Gateway.php +++ b/module/VuFind/src/VuFind/Db/Table/Gateway.php @@ -105,12 +105,24 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa parent::initialize(); if (null !== $this->rowClass) { $resultSetPrototype = $this->getResultSetPrototype(); - $prototype = new $this->rowClass($this->getAdapter()); - if ($prototype instanceof ServiceLocatorAwareInterface) { - $prototype->setServiceLocator($this->getServiceLocator()); - } - $resultSetPrototype->setArrayObjectPrototype($prototype); + $resultSetPrototype->setArrayObjectPrototype( + $this->initializeRowPrototype() + ); + } + } + + /** + * Construct the prototype for rows. + * + * @return object + */ + protected function initializeRowPrototype() + { + $prototype = new $this->rowClass($this->getAdapter()); + if ($prototype instanceof ServiceLocatorAwareInterface) { + $prototype->setServiceLocator($this->getServiceLocator()); } + return $prototype; } /** diff --git a/module/VuFind/src/VuFind/Db/Table/User.php b/module/VuFind/src/VuFind/Db/Table/User.php index b65942e52a7f4cada3812eb89ca0fd61abe85f11..9978af7f188e7d1c2d43ce7b4f72cb4bc8c0f09f 100644 --- a/module/VuFind/src/VuFind/Db/Table/User.php +++ b/module/VuFind/src/VuFind/Db/Table/User.php @@ -38,12 +38,22 @@ namespace VuFind\Db\Table; */ class User extends Gateway { + /** + * VuFind configuration + * + * @var \Zend\Config\Config + */ + protected $config; + /** * Constructor + * + * @param \Zend\Config\Config $config VuFind configuration */ - public function __construct() + public function __construct(\Zend\Config\Config $config) { parent::__construct('user', 'VuFind\Db\Row\User'); + $this->config = $config; } /** @@ -94,6 +104,18 @@ class User extends Gateway return $this->select($callback); } + /** + * Construct the prototype for rows. + * + * @return object + */ + protected function initializeRowPrototype() + { + $prototype = parent::initializeRowPrototype(); + $prototype->setConfig($this->config); + return $prototype; + } + /** * Return a row by a verification hash *