1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-14 20:54:13 +02:00

[ticket/17135] Refactor messenger code to services [ci skip]

PHPBB3-17135
This commit is contained in:
rxu
2023-06-06 16:41:55 +07:00
parent 5be1f5d5c9
commit 1f952ca6d8
6 changed files with 99 additions and 57 deletions

View File

@@ -141,7 +141,7 @@ class message
'user_email' => $recipient_address,
'lang' => $recipient_lang,
'username' => $recipient_username,
'user_jabber' => $recipient_jabber,
'user_jabber' => $recipient_jabber,
'notify_type' => $recipient_notify_type,
'to_name' => $recipient_name,
);
@@ -245,7 +245,7 @@ class message
foreach ($this->recipients as $recipient)
{
$messenger_collection_iterator = $this->messenger->getIterator();
$messenger_collection_iterator = $messenger->getIterator();
while ($messenger_collection_iterator->valid())
{
$messenger_method = $messenger_collection_iterator->current();
@@ -256,15 +256,15 @@ class message
$messenger_method->set_addresses($recipient);
$messenger_method->replyto($this->sender_address);
$messenger_method->headers('X-AntiAbuse', 'Board servername - ' . $this->server_name);
$messenger_method->headers('X-AntiAbuse', 'User IP - ' . $this->sender_ip);
$messenger_method->header('X-AntiAbuse', 'Board servername - ' . $this->server_name);
$messenger_method->header('X-AntiAbuse', 'User IP - ' . $this->sender_ip);
if ($this->sender_id)
{
$messenger_method->headers('X-AntiAbuse', 'User_id - ' . $this->sender_id);
$messenger_method->header('X-AntiAbuse', 'User_id - ' . $this->sender_id);
}
if ($this->sender_username)
{
$messenger_method->headers('X-AntiAbuse', 'Username - ' . $this->sender_username);
$messenger_method->header('X-AntiAbuse', 'Username - ' . $this->sender_username);
}
$messenger_method->subject(html_entity_decode($this->subject, ENT_COMPAT));

View File

@@ -25,14 +25,11 @@ use phpbb\user;
/**
* Messenger base class
*/
class base
abstract class base
{
/** @var array */
protected $additional_headers = [];
/** @var array */
protected $addresses = [];
/** @var config */
protected $config;
@@ -90,6 +87,15 @@ class base
$this->set_use_queue();
}
/**
* Get messenger method id
* @return mixed
*/
abstract public function get_id()
{
return;
}
/**
* Sets the use of messenger queue flag
*
@@ -105,10 +111,12 @@ class base
*
* @return void
*/
public function reset()
abstract public function reset()
{
$this->addresses = [];
$this->subject = $this->additional_headers = [];
$this->msg = '';
$this->use_queue = true;
unset($this->template);
}
/**
@@ -117,7 +125,7 @@ class base
* @param array $user User row
* @return void
*/
public function set_addresses($user)
abstract public function set_addresses($user)
{
}
@@ -164,6 +172,14 @@ class base
{
}
/**
* Send out messages
* @return bool
*/
abstract protected function send()
{
}
/**
* Set email template to use
*
@@ -295,7 +311,7 @@ class base
'SITENAME' => html_entity_decode($this->config['sitename'], ENT_COMPAT),
]);
$subject = $this->email->getSubject();
$subject = $this->subject;
$template = $this->template;
/**
* Event to modify the template before parsing
@@ -304,7 +320,7 @@ class base
* @var string subject The message subject
* @var \phpbb\template\template template The (readonly) template object
* @since 3.2.4-RC1
* @changed 4.0.0-a1 Added vars: email. Removed vars: method, break.
* @changed 4.0.0-a1 Removed vars: method, break.
*/
$vars = ['subject', 'template'];
extract($this->dispatcher->trigger_event('core.modify_notification_template', compact($vars)));
@@ -378,7 +394,7 @@ class base
}
/**
* Save message data to the messemger file queue
* Save message data to the messenger file queue
* @return void
*/
public function save_queue()

View File

@@ -106,12 +106,14 @@ class email extends base
*
* @return void
*/
public function init()
public function reset()
{
$this->email = new Email();
$this->headers = $this->email->getHeaders();
$this->msg = $this->replyto = $this->from = '';
$this->mail_priority = Email::PRIORITY_NORMAL;
parent::reset();
}
/**
@@ -567,6 +569,7 @@ class email extends base
'email' => $this->email,
]);
}
$this->reset();
return true;
}

View File

@@ -393,6 +393,19 @@ class jabber extends base
$this->to[$pos]['name'] = trim($realname);
}
/**
* Inits/resets the data to default
*
* @return void
*/
public function reset()
{
$this->msg = '';
$this->to = [];
parent::reset();
}
/**
* Sets the use of messenger queue flag
*
@@ -455,6 +468,8 @@ class jabber extends base
}
unset($addresses);
$this->reset();
return true;
}