diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-08-10 15:23:15 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-08-10 15:23:15 +0200 |
commit | 54b0ebc4106b985053e0c1827283e77fcfb596af (patch) | |
tree | c024029d308d89ed7279fcc50de955a629f8f445 /phpBB | |
parent | 472fe9fe60fc60a8f540456736e10f92b9809cd6 (diff) | |
parent | f0852dcf1af3b0c99cfa71618b543b4f7ab7ccbe (diff) | |
download | forums-54b0ebc4106b985053e0c1827283e77fcfb596af.tar forums-54b0ebc4106b985053e0c1827283e77fcfb596af.tar.gz forums-54b0ebc4106b985053e0c1827283e77fcfb596af.tar.bz2 forums-54b0ebc4106b985053e0c1827283e77fcfb596af.tar.xz forums-54b0ebc4106b985053e0c1827283e77fcfb596af.zip |
Merge pull request #2862 from marc1706/ticket/12932
[ticket/12932] Add method for allowing override of \phpbb\datetime class
* marc1706/ticket/12932:
[ticket/12932] Remove set_datetime_class method from user class
[ticket/12932] Fix tests and calls to create_datetime
[ticket/12932] Add method for getting the datetime class and allow overriding
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/config/parameters.yml | 2 | ||||
-rw-r--r-- | phpBB/config/services.yml | 3 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 4 | ||||
-rw-r--r-- | phpBB/install/index.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/user.php | 11 |
6 files changed, 18 insertions, 6 deletions
diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml new file mode 100644 index 0000000000..5bf2c678ee --- /dev/null +++ b/phpBB/config/parameters.yml @@ -0,0 +1,2 @@ +parameters: + datetime.class: \phpbb\datetime diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index a9f9f5ed19..6b06deb256 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -10,6 +10,7 @@ imports: - { resource: mimetype_guessers.yml } - { resource: passwords.yml } - { resource: profilefields.yml } + - { resource: parameters.yml } services: acl.permissions: @@ -346,6 +347,8 @@ services: user: class: phpbb\user + arguments: + - %datetime.class% user_loader: class: phpbb\user_loader diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 53ccf2df2c..6a2edb0d58 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1061,7 +1061,7 @@ function phpbb_timezone_select($user, $default = '', $truncate = false) foreach ($unsorted_timezones as $timezone) { $tz = new DateTimeZone($timezone); - $dt = new \phpbb\datetime($user, 'now', $tz); + $dt = $user->create_datetime('now', $tz); $offset = $dt->getOffset(); $current_time = $dt->format($user->lang['DATETIME_FORMAT'], true); $offset_string = phpbb_format_timezone_offset($offset); @@ -4881,7 +4881,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id = } } - $dt = new \phpbb\datetime($user, 'now', $user->timezone); + $dt = $user->create_datetime(); $timezone_offset = 'GMT' . phpbb_format_timezone_offset($dt->getOffset()); $timezone_name = $user->timezone->getName(); if (isset($user->lang['timezones'][$timezone_name])) diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 395aff6c7d..2e497da3db 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -240,7 +240,7 @@ $sub = $request->variable('sub', ''); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -$user = new \phpbb\user(); +$user = new \phpbb\user('\phpbb\datetime'); $auth = new \phpbb\auth\auth(); // Add own hook handler, if present. :o diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php index 6335c75398..58845b88ec 100644 --- a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php @@ -121,7 +121,7 @@ class soft_delete_mod_convert extends \phpbb\db\migration\migration new \phpbb\auth\auth(), $this->config, $this->db, - new \phpbb\user(), + new \phpbb\user('\phpbb\datetime'), $this->phpbb_root_path, $this->php_ext, $this->table_prefix . 'forums', diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index 4e90044395..ea98034434 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -31,6 +31,11 @@ class user extends \phpbb\session */ public $timezone; + /** + * @var string Class name of datetime object + */ + protected $datetime; + var $lang_name = false; var $lang_id = false; var $lang_path; @@ -42,12 +47,14 @@ class user extends \phpbb\session /** * Constructor to set the lang path + * @param string $datetime_class Class name of datetime class */ - function __construct() + function __construct($datetime_class) { global $phpbb_root_path; $this->lang_path = $phpbb_root_path . 'language/'; + $this->datetime = $datetime_class; } /** @@ -727,7 +734,7 @@ class user extends \phpbb\session public function create_datetime($time = 'now', \DateTimeZone $timezone = null) { $timezone = $timezone ?: $this->timezone; - return new \phpbb\datetime($this, $time, $timezone); + return new $this->datetime($this, $time, $timezone); } /** |