[feature/passwords] Use dependency injection for helper

This will now be used instead of manually loading the passwords helper
instance in the passwords manager.

PHPBB3-11610
This commit is contained in:
Marc Alexander 2013-09-22 21:17:30 +02:00
parent 1970c69c8c
commit f5eb0d744e
4 changed files with 21 additions and 9 deletions

View file

@ -50,4 +50,8 @@ services:
arguments: arguments:
- @config - @config
- @passwords.driver_collection - @passwords.driver_collection
- @passwords.helper
- %passwords.algorithm% - %passwords.algorithm%
passwords.helper:
class: phpbb_passwords_helper

View file

@ -26,14 +26,17 @@ class phpbb_passwords_helper
protected $manager; protected $manager;
/** /**
* Construct a phpbb_passwords_helper object * Set the passwords manager instance
* *
* @param phpbb_passwords_manager $manager Crypto manager object * @param phpbb_passwords_manager $manager Crypto manager object
*/ */
public function __construct($manager) public function set_manager(phpbb_passwords_manager $manager)
{
if ($this->manager === null)
{ {
$this->manager = $manager; $this->manager = $manager;
} }
}
/** /**
* Get hash settings from combined hash * Get hash settings from combined hash

View file

@ -60,15 +60,16 @@ class phpbb_passwords_manager
* @param phpbb_config $config phpBB configuration * @param phpbb_config $config phpBB configuration
* @param phpbb_di_service_collection $hashing_algorithms Hashing driver * @param phpbb_di_service_collection $hashing_algorithms Hashing driver
* service collection * service collection
* @param phpbb_passwords_helper $helper Passwords helper object
* @param string $default Default driver name * @param string $default Default driver name
*/ */
public function __construct($config, $hashing_algorithms, $default) public function __construct($config, $hashing_algorithms, $helper, $default)
{ {
$this->config = $config; $this->config = $config;
$this->type = $default; $this->type = $default;
$this->fill_type_map($hashing_algorithms); $this->fill_type_map($hashing_algorithms);
$this->load_passwords_helper(); $this->load_passwords_helper($helper);
} }
/** /**
@ -94,12 +95,15 @@ class phpbb_passwords_manager
/** /**
* Load passwords helper class * Load passwords helper class
*
* @param phpbb_passwords_helper $helper Passwords helper object
*/ */
protected function load_passwords_helper() protected function load_passwords_helper($helper)
{ {
if ($this->helper === null) if ($this->helper === null)
{ {
$this->helper = new phpbb_passwords_helper($this); $this->helper = $helper;
$this->helper->set_manager($this);
} }
} }

View file

@ -40,8 +40,9 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
$this->phpbb_container->set($key, $driver); $this->phpbb_container->set($key, $driver);
} }
// Set up avatar manager $this->helper = new phpbb_passwords_helper;
$this->manager = new phpbb_passwords_manager($config, $this->passwords_drivers, 'passwords.driver.bcrypt_2y'); // Set up passwords manager
$this->manager = new phpbb_passwords_manager($config, $this->passwords_drivers, $this->helper, 'passwords.driver.bcrypt_2y');
} }
public function hash_password_data() public function hash_password_data()