Permalink
Browse files

Moved configuration retrieval to bootstrap

- Created _initConfig() method in bootstrap
  - _initHelpers() method now relies on this, and passes the config on to helper
    constructors
- Updated HandleLogin helper to get configuration via constructor, and stores it
  in protected member
  • Loading branch information...
weierophinney committed Oct 1, 2010
1 parent 7fc7d58 commit e9cb533ead6eb5003d1b024f953a4b71d643d9d2
@@ -8,10 +8,23 @@ public function initResourceLoader()
$loader->addResourceType('helper', 'helpers', 'Helper');
}
+ protected function _initConfig()
+ {
+ $env = $this->getEnvironment();
+ $config = new Zend_Config_Ini(
+ dirname(__FILE__) . '/configs/user.ini',
+ $this->getEnvironment()
+ );
+ return $config;
+ }
+
protected function _initHelpers()
{
+ $this->bootstrap('config');
+ $config = $this->getResource('config');
+
Zend_Controller_Action_HelperBroker::addHelper(
- new User_Helper_HandleLogin()
+ new User_Helper_HandleLogin($config)
);
}
}
@@ -2,6 +2,13 @@
class User_Helper_HandleLogin extends Zend_Controller_Action_Helper_Abstract
{
+ protected $config;
+
+ public function __construct(Zend_Config $config)
+ {
+ $this->config = $config;
+ }
+
public function preDispatch()
{
if (null === ($controller = $this->getActionController())) {
@@ -54,17 +61,16 @@ public function handleLogin()
return;
}
- $config = $this->getConfig();
$username = $form->username->getValue();
$password = $form->password->getValue();
- $password = substr($username, 0, 3) . $password . $config->salt;
+ $password = substr($username, 0, 3) . $password . $this->config->salt;
$password = hash('sha256', $password);
$adapter = new Zend_Auth_Adapter_DbTable(
Zend_Db_Table_Abstract::getDefaultAdapter(),
- $config->adapter->table,
- $config->adapter->identity_column,
- $config->adapter->password_column
+ $this->config->adapter->table,
+ $this->config->adapter->identity_column,
+ $this->config->adapter->password_column
);
$adapter->setIdentity($username)
->setCredential($password);
@@ -83,14 +89,6 @@ public function handleLogin()
$this->createProfileWidget();
}
- public function getConfig()
- {
- if (null === $this->config) {
- $this->config = new Zend_Config_Ini(dirname(__FILE__) . '/../configs/user.ini', APPLICATION_ENV);
- }
- return $this->config;
- }
-
public function getView()
{
$controller = $this->getActionController();

0 comments on commit e9cb533

Please sign in to comment.