Skip to content

Commit a99b080

Browse files
Crizz0marc1706
authored andcommitted
[ticket/17191] Use di and avoid circular ref
PHPBB3-17191
1 parent aa8a38a commit a99b080

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

feed/controller/feed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ protected function send_feed_do(feed_interface $feed)
395395
'FEED_TITLE' => $this->config['sitename'],
396396
'FEED_SUBTITLE' => $this->config['site_desc'],
397397
'FEED_UPDATED' => $this->feed_helper->format_date($feed_updated_time),
398-
'FEED_LANG' => $this->lang_helper->get_lang_key_value('user_lang'),
398+
'FEED_LANG' => $this->lang_helper->get_lang_key_value('user_lang', $user->data['user_lang']),
399399
'FEED_AUTHOR' => $this->config['sitename'],
400400

401401
// Feed entries

install/controller/helper.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,16 @@ public function handle_navigation($iohandler = null)
253253
*/
254254
protected function page_header($page_title, $selected_language = false)
255255
{
256-
global $phpbb_container;
256+
global $user;
257257

258258
// Path to templates
259259
$paths = array($this->phpbb_root_path . 'install/update/new/adm/', $this->phpbb_admin_path);
260260
$paths = array_filter($paths, 'is_dir');
261261
$path = array_shift($paths);
262262
$path = substr($path, strlen($this->phpbb_root_path));
263-
// Get the language helper
264-
/* @var $language_helper \phpbb\language\language_file_helper */
265-
$language_file_helper = $phpbb_container->get('language.helper.language_file');
266263

267264
// Grab the users lang direction and store it for later use
268-
$direction = $language_file_helper->get_lang_key_value('direction');
265+
$direction = $this->lang_helper->get_lang_key_value('direction', $user->data['user_lang']);
269266

270267
$this->template->assign_vars(array(
271268
'L_CHANGE' => $this->language->lang('CHANGE'),
@@ -285,7 +282,7 @@ protected function page_header($page_title, $selected_language = false)
285282
'S_CONTENT_ENCODING' => 'UTF-8',
286283
'S_LANG_SELECT' => $selected_language,
287284

288-
'S_USER_LANG' => $language_file_helper->get_lang_key_value('user_lang'),
285+
'S_USER_LANG' => $this->lang_helper->get_lang_key_value('user_lang', $user->data['user_lang']),
289286
));
290287

291288
$this->render_navigation();

language/language.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace phpbb\language;
1515

16+
use phpbb\config\config;
1617
use phpbb\language\exception\invalid_plural_rule_exception;
1718

1819
/**
@@ -70,15 +71,29 @@ class language
7071
*/
7172
protected $loader;
7273

74+
/**
75+
* @var language_file_helper
76+
*/
77+
protected $lang_helper;
78+
79+
/**
80+
* @var \phpbb\config\config
81+
*/
82+
protected $config;
83+
7384
/**
7485
* Constructor
7586
*
7687
* @param \phpbb\language\language_file_loader $loader Language file loader
88+
* @param language_file_helper $lang_helper
7789
* @param array|null $common_modules Array of common language modules to load (optional)
90+
* @param config $config The config
7891
*/
79-
public function __construct(language_file_loader $loader, $common_modules = null)
92+
public function __construct(language_file_loader $loader, language_file_helper $lang_helper, config $config, $common_modules = null)
8093
{
8194
$this->loader = $loader;
95+
$this->lang_helper = $lang_helper;
96+
$this->config = $config;
8297

8398
// Set up default information
8499
$this->user_language = null;
@@ -403,13 +418,10 @@ protected function load_common_language_files()
403418
*/
404419
public function get_plural_form($number, $force_rule = false)
405420
{
406-
global $phpbb_container;
407-
// Get the language helper
408-
/* @var $language_helper \phpbb\language\language_file_helper */
409-
$language_file_helper = $phpbb_container->get('language.helper.language_file');
421+
global $user;
410422

411423
// Grab the users lang plural rule
412-
$plural_rule_content = $language_file_helper->get_lang_key_value('plural_rule');
424+
$plural_rule_content = $this->lang_helper->get_lang_key_value('plural_rule', $user->data['user_lang']);
413425

414426
$number = (int) $number;
415427
$plural_rule = ($force_rule !== false) ? $force_rule : ((isset($plural_rule_content)) ? $plural_rule_content : 1);

language/language_file_helper.php

+15-10
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
use DomainException;
1717
use phpbb\json\sanitizer as json_sanitizer;
18-
use phpbb\user;
1918
use Symfony\Component\Finder\Finder;
19+
use phpbb\config\config;
2020

2121
/**
2222
* Helper class for language file related functions
@@ -28,19 +28,22 @@ class language_file_helper
2828
*/
2929
protected $phpbb_root_path;
3030

31-
/** @var user */
32-
protected $user;
31+
/**
32+
* @var \phpbb\config\config
33+
*/
34+
protected $config;
3335

3436
/**
3537
* Constructor
3638
*
37-
* @param string $phpbb_root_path Path to phpBB's root
38-
* @param user $user User Object
39+
* @param string $phpbb_root_path Path to phpBB's root
40+
* @param config $config The config
41+
*
3942
*/
40-
public function __construct(string $phpbb_root_path, \phpbb\user $user)
43+
public function __construct(string $phpbb_root_path, config $config)
4144
{
4245
$this->phpbb_root_path = $phpbb_root_path;
43-
$this->user = $user;
46+
$this->config = $config;
4447
}
4548

4649
/**
@@ -79,16 +82,18 @@ public function get_available_languages() : array
7982
* @return string
8083
*
8184
*/
82-
public function get_lang_key_value($lang_key) : string
85+
public function get_lang_key_value($lang_key, $user_lang_db) : string
8386
{
8487
$available_languages = $this->get_available_languages();
8588

8689
foreach ($available_languages as $key => $value)
8790
{
8891
$available_languages[$value['iso']] = $value;
92+
unset($available_languages[$key]);
8993
}
90-
$user_lang = $this->user->data['user_lang'] ?? 'en';
91-
return $available_languages[$user_lang][$lang_key];
94+
$board_default_lang = $this->config['default_lang'];
95+
$user_lang_db = $user_lang_db ?? $board_default_lang;
96+
return $available_languages[$user_lang_db][$lang_key];
9297
}
9398

9499
/**

0 commit comments

Comments
 (0)