ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMailMimeSenderFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
24  protected array $senders = [];
25  protected int $anonymous_usr_id = 0;
26 
27  public function __construct(
28  protected ilSetting $settings,
29  protected ilMustacheFactory $mustache_factory,
30  ?int $anonymous_usr_id = null
31  ) {
32  if ($anonymous_usr_id === null && defined('ANONYMOUS_USER_ID')) {
33  $anonymous_usr_id = ANONYMOUS_USER_ID;
34  }
35  if ($anonymous_usr_id === null) {
36  throw new Exception();
37  }
38 
39  $this->anonymous_usr_id = $anonymous_usr_id;
40  }
41 
42  protected function isSystemMail(int $usr_id): bool
43  {
44  return $usr_id === $this->anonymous_usr_id;
45  }
46 
47  public function getSenderByUsrId(int $usr_id): ilMailMimeSender
48  {
49  if (array_key_exists($usr_id, $this->senders)) {
50  return $this->senders[$usr_id];
51  }
52 
53  if ($this->isSystemMail($usr_id)) {
54  $sender = $this->system();
55  } else {
56  $sender = $this->user($usr_id);
57  }
58 
59  $this->senders[$usr_id] = $sender;
60 
61  return $sender;
62  }
63 
64  public function system(): ilMailMimeSenderSystem
65  {
66  return new ilMailMimeSenderSystem($this->settings);
67  }
68 
69  public function user(int $usr_id): ilMailMimeSenderUser
70  {
71  return new ilMailMimeSenderUserById($this->settings, $usr_id, $this->mustache_factory);
72  }
73 
74  public function userByEmailAddress(string $email_address): ilMailMimeSenderUser
75  {
76  return new ilMailMimeSenderUserByEmailAddress($this->settings, $email_address, $this->mustache_factory);
77  }
78 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
__construct(protected ilSetting $settings, protected ilMustacheFactory $mustache_factory, ?int $anonymous_usr_id=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
userByEmailAddress(string $email_address)