mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[feature/passwords] Pass config via service container to driver helper
This will get rid of the global $config in the driver helper PHPBB3-11610
This commit is contained in:
parent
de087d537e
commit
3ebff0a960
3 changed files with 23 additions and 7 deletions
|
@ -51,6 +51,8 @@ services:
|
||||||
|
|
||||||
passwords.driver_helper:
|
passwords.driver_helper:
|
||||||
class: phpbb\passwords\driver\helper
|
class: phpbb\passwords\driver\helper
|
||||||
|
arguments:
|
||||||
|
- @config
|
||||||
|
|
||||||
passwords.manager:
|
passwords.manager:
|
||||||
class: phpbb\passwords\manager
|
class: phpbb\passwords\manager
|
||||||
|
|
|
@ -22,12 +22,27 @@ if (!defined('IN_PHPBB'))
|
||||||
*/
|
*/
|
||||||
class helper
|
class helper
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var phpbb\config\config
|
||||||
|
*/
|
||||||
|
protected $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* base64 alphabet
|
* base64 alphabet
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
public $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a driver helper object
|
||||||
|
*
|
||||||
|
* @param phpbb\config\config $config phpBB configuration
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\config\config $config)
|
||||||
|
{
|
||||||
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base64 encode hash
|
* Base64 encode hash
|
||||||
*
|
*
|
||||||
|
@ -86,16 +101,15 @@ class helper
|
||||||
public function unique_id($extra = 'c')
|
public function unique_id($extra = 'c')
|
||||||
{
|
{
|
||||||
static $dss_seeded = false;
|
static $dss_seeded = false;
|
||||||
global $config;
|
|
||||||
|
|
||||||
$val = $config['rand_seed'] . microtime();
|
$val = $this->config['rand_seed'] . microtime();
|
||||||
$val = md5($val);
|
$val = md5($val);
|
||||||
$config['rand_seed'] = md5($config['rand_seed'] . $val . $extra);
|
$this->config['rand_seed'] = md5($this->config['rand_seed'] . $val . $extra);
|
||||||
|
|
||||||
if ($dss_seeded !== true && ($config['rand_seed_last_update'] < time() - rand(1,10)))
|
if ($dss_seeded !== true && ($this->config['rand_seed_last_update'] < time() - rand(1,10)))
|
||||||
{
|
{
|
||||||
set_config('rand_seed_last_update', time(), true);
|
$this->config->set('rand_seed_last_update', time(), true);
|
||||||
set_config('rand_seed', $config['rand_seed'], true);
|
$this->config->set('rand_seed', $this->config['rand_seed'], true);
|
||||||
$dss_seeded = true;
|
$dss_seeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
// Prepare dependencies for manager and driver
|
// Prepare dependencies for manager and driver
|
||||||
$config = new \phpbb\config\config(array());
|
$config = new \phpbb\config\config(array());
|
||||||
$driver_helper = new phpbb\passwords\driver\helper;
|
$driver_helper = new phpbb\passwords\driver\helper($config);
|
||||||
|
|
||||||
$this->passwords_drivers = array(
|
$this->passwords_drivers = array(
|
||||||
'passwords.driver.bcrypt' => new phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
'passwords.driver.bcrypt' => new phpbb\passwords\driver\bcrypt($config, $driver_helper),
|
||||||
|
|
Loading…
Add table
Reference in a new issue