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

Eliminated dependency on service manager.

parent 5ef89541
No related merge requests found
...@@ -322,6 +322,7 @@ $config = array( ...@@ -322,6 +322,7 @@ $config = array(
'abstract_factories' => array('VuFind\Db\Table\PluginFactory'), 'abstract_factories' => array('VuFind\Db\Table\PluginFactory'),
'factories' => array( 'factories' => array(
'resource' => 'VuFind\Db\Table\Factory::getResource', 'resource' => 'VuFind\Db\Table\Factory::getResource',
'user' => 'VuFind\Db\Table\Factory::getUser',
), ),
'invokables' => array( 'invokables' => array(
'changetracker' => 'VuFind\Db\Table\ChangeTracker', 'changetracker' => 'VuFind\Db\Table\ChangeTracker',
...@@ -331,7 +332,6 @@ $config = array( ...@@ -331,7 +332,6 @@ $config = array(
'search' => 'VuFind\Db\Table\Search', 'search' => 'VuFind\Db\Table\Search',
'session' => 'VuFind\Db\Table\Session', 'session' => 'VuFind\Db\Table\Session',
'tags' => 'VuFind\Db\Table\Tags', 'tags' => 'VuFind\Db\Table\Tags',
'user' => 'VuFind\Db\Table\User',
'userlist' => 'VuFind\Db\Table\UserList', 'userlist' => 'VuFind\Db\Table\UserList',
'userresource' => 'VuFind\Db\Table\UserResource', 'userresource' => 'VuFind\Db\Table\UserResource',
'userstats' => 'VuFind\Db\Table\UserStats', 'userstats' => 'VuFind\Db\Table\UserStats',
......
...@@ -58,6 +58,13 @@ class User extends ServiceLocatorAwareGateway ...@@ -58,6 +58,13 @@ class User extends ServiceLocatorAwareGateway
*/ */
protected $encryptionKey = null; protected $encryptionKey = null;
/**
* VuFind configuration
*
* @var \Zend\Config\Config
*/
protected $config = null;
/** /**
* Constructor * Constructor
* *
...@@ -68,6 +75,18 @@ class User extends ServiceLocatorAwareGateway ...@@ -68,6 +75,18 @@ class User extends ServiceLocatorAwareGateway
parent::__construct('id', 'user', $adapter); 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. * Reset ILS login credentials.
* *
...@@ -124,11 +143,9 @@ class User extends ServiceLocatorAwareGateway ...@@ -124,11 +143,9 @@ class User extends ServiceLocatorAwareGateway
protected function passwordEncryptionEnabled() protected function passwordEncryptionEnabled()
{ {
if (null === $this->encryptionEnabled) { if (null === $this->encryptionEnabled) {
$config = $this->getServiceLocator()->getServiceLocator()
->get('VuFind\Config')->get('config');
$this->encryptionEnabled $this->encryptionEnabled
= isset($config->Authentication->encrypt_ils_password) = isset($this->config->Authentication->encrypt_ils_password)
? $config->Authentication->encrypt_ils_password : false; ? $this->config->Authentication->encrypt_ils_password : false;
} }
return $this->encryptionEnabled; return $this->encryptionEnabled;
} }
...@@ -153,16 +170,14 @@ class User extends ServiceLocatorAwareGateway ...@@ -153,16 +170,14 @@ class User extends ServiceLocatorAwareGateway
// Load encryption key from configuration if not already present: // Load encryption key from configuration if not already present:
if (null === $this->encryptionKey) { if (null === $this->encryptionKey) {
$config = $this->getServiceLocator()->getServiceLocator() if (!isset($this->config->Authentication->ils_encryption_key)
->get('VuFind\Config')->get('config'); || empty($this->config->Authentication->ils_encryption_key)
if (!isset($config->Authentication->ils_encryption_key)
|| empty($config->Authentication->ils_encryption_key)
) { ) {
throw new \VuFind\Exception\PasswordSecurity( throw new \VuFind\Exception\PasswordSecurity(
'ILS password encryption on, but no key set.' '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: // Perform encryption:
......
...@@ -51,4 +51,18 @@ class Factory ...@@ -51,4 +51,18 @@ class Factory
{ {
return new Resource($sm->getServiceLocator()->get('VuFind\DateConverter')); 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
...@@ -105,12 +105,24 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa ...@@ -105,12 +105,24 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa
parent::initialize(); parent::initialize();
if (null !== $this->rowClass) { if (null !== $this->rowClass) {
$resultSetPrototype = $this->getResultSetPrototype(); $resultSetPrototype = $this->getResultSetPrototype();
$prototype = new $this->rowClass($this->getAdapter()); $resultSetPrototype->setArrayObjectPrototype(
if ($prototype instanceof ServiceLocatorAwareInterface) { $this->initializeRowPrototype()
$prototype->setServiceLocator($this->getServiceLocator()); );
} }
$resultSetPrototype->setArrayObjectPrototype($prototype); }
/**
* 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;
} }
/** /**
......
...@@ -38,12 +38,22 @@ namespace VuFind\Db\Table; ...@@ -38,12 +38,22 @@ namespace VuFind\Db\Table;
*/ */
class User extends Gateway class User extends Gateway
{ {
/**
* VuFind configuration
*
* @var \Zend\Config\Config
*/
protected $config;
/** /**
* Constructor * 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'); parent::__construct('user', 'VuFind\Db\Row\User');
$this->config = $config;
} }
/** /**
...@@ -94,6 +104,18 @@ class User extends Gateway ...@@ -94,6 +104,18 @@ class User extends Gateway
return $this->select($callback); 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 * Return a row by a verification hash
* *
......
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