From 52fac451a3008978a30078492736f6fa1e1b89c5 Mon Sep 17 00:00:00 2001 From: lavigor Date: Sat, 9 Jun 2018 19:52:21 +0300 Subject: [PATCH] [ticket/13713] Create abstract parent service for user source PHPBB3-13713 --- .../default/container/services_mention.yml | 29 +++++++------------ phpBB/phpbb/mention/source/friend.php | 8 ++--- .../textformatter/s9e/mention_helper.php | 20 ++++++------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/phpBB/config/default/container/services_mention.yml b/phpBB/config/default/container/services_mention.yml index 8b466b3b01..06c94d54b3 100644 --- a/phpBB/config/default/container/services_mention.yml +++ b/phpBB/config/default/container/services_mention.yml @@ -18,44 +18,37 @@ services: phpbb.mention.source.friend: class: phpbb\mention\source\friend - arguments: - - '@dbal.conn' - - '@user_loader' - - '@user' - - '%core.root_path%' - - '%core.php_ext%' + parent: phpbb.mention.source.user + calls: + - [set_user, ['@user']] tags: - { name: mention.source } phpbb.mention.source.member: class: phpbb\mention\source\member - arguments: - - '@dbal.conn' - - '@user_loader' - - '%core.root_path%' - - '%core.php_ext%' + parent: phpbb.mention.source.user tags: - { name: mention.source } phpbb.mention.source.team: class: phpbb\mention\source\team - arguments: - - '@dbal.conn' - - '@user_loader' - - '%core.root_path%' - - '%core.php_ext%' + parent: phpbb.mention.source.user tags: - { name: mention.source } phpbb.mention.source.topic: class: phpbb\mention\source\topic + parent: phpbb.mention.source.user + tags: + - { name: mention.source } + + phpbb.mention.source.user: + abstract: true arguments: - '@dbal.conn' - '@user_loader' - '%core.root_path%' - '%core.php_ext%' - tags: - - { name: mention.source } phpbb.mention.source.usergroup: class: phpbb\mention\source\usergroup diff --git a/phpBB/phpbb/mention/source/friend.php b/phpBB/phpbb/mention/source/friend.php index d63efa4c72..b3c6a1898b 100644 --- a/phpBB/phpbb/mention/source/friend.php +++ b/phpBB/phpbb/mention/source/friend.php @@ -19,13 +19,13 @@ class friend extends user protected $user; /** - * Constructor + * Set the user service used to retrieve current user ID + * + * @param \phpbb\user $user */ - public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user_loader $user_loader, \phpbb\user $user, $phpbb_root_path, $phpEx) + public function set_user(\phpbb\user $user) { $this->user = $user; - - parent::__construct($db, $user_loader, $phpbb_root_path, $phpEx); } /** diff --git a/phpBB/phpbb/textformatter/s9e/mention_helper.php b/phpBB/phpbb/textformatter/s9e/mention_helper.php index 66092dbbc5..c693151f1f 100644 --- a/phpBB/phpbb/textformatter/s9e/mention_helper.php +++ b/phpBB/phpbb/textformatter/s9e/mention_helper.php @@ -35,7 +35,7 @@ class mention_helper /** * @var array Array of users' and groups' colors for each cached ID */ - protected $cached_colors = []; + protected $cached_colours = []; /** * Constructor @@ -59,9 +59,9 @@ class mention_helper */ protected function get_colors($user_ids, $group_ids) { - $this->cached_colors = []; - $this->cached_colors['users'] = []; - $this->cached_colors['groups'] = []; + $this->cached_colours = []; + $this->cached_colours['users'] = []; + $this->cached_colours['groups'] = []; if (!empty($user_ids)) { @@ -78,7 +78,7 @@ class mention_helper while ($row = $this->db->sql_fetchrow($result)) { - $this->cached_colors['users'][$row['user_id']] = $row['user_colour']; + $this->cached_colours['users'][$row['user_id']] = $row['user_colour']; } $this->db->sql_freeresult($result); @@ -97,7 +97,7 @@ class mention_helper while ($row = $this->db->sql_fetchrow($result)) { - $this->cached_colors['groups'][$row['group_id']] = $row['group_colour']; + $this->cached_colours['groups'][$row['group_id']] = $row['group_colour']; } $this->db->sql_freeresult($result); @@ -130,18 +130,18 @@ class mention_helper { $attributes['profile_url'] = str_replace('{USER_ID}', $attributes['user_id'], $user_profile_url); - if (!empty($this->cached_colors['users'][$attributes['user_id']])) + if (!empty($this->cached_colours['users'][$attributes['user_id']])) { - $attributes['color'] = $this->cached_colors['users'][$attributes['user_id']]; + $attributes['color'] = $this->cached_colours['users'][$attributes['user_id']]; } } else if (isset($attributes['group_id'])) { $attributes['profile_url'] = str_replace('{GROUP_ID}', $attributes['group_id'], $group_profile_url); - if (!empty($this->cached_colors['groups'][$attributes['group_id']])) + if (!empty($this->cached_colours['groups'][$attributes['group_id']])) { - $attributes['color'] = $this->cached_colors['groups'][$attributes['group_id']]; + $attributes['color'] = $this->cached_colours['groups'][$attributes['group_id']]; } }