ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailMimeSenderFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  protected ilSetting $settings;
29  protected array $senders = [];
30  protected int $anonymousUsrId = 0;
31 
32  public function __construct(ilSetting $settings, int $anonymousUsrId = null)
33  {
34  $this->settings = $settings;
35  if (null === $anonymousUsrId && defined('ANONYMOUS_USER_ID')) {
36  $anonymousUsrId = ANONYMOUS_USER_ID;
37  }
38  if (null === $anonymousUsrId) {
39  throw new Exception();
40  }
41 
42  $this->anonymousUsrId = $anonymousUsrId;
43  }
44 
45  protected function isSystemMail(int $usrId): bool
46  {
47  return $usrId === $this->anonymousUsrId;
48  }
49 
50  public function getSenderByUsrId(int $usrId): ilMailMimeSender
51  {
52  if (array_key_exists($usrId, $this->senders)) {
53  return $this->senders[$usrId];
54  }
55 
56  if ($this->isSystemMail($usrId)) {
57  $sender = $this->system();
58  } else {
59  $sender = $this->user($usrId);
60  }
61 
62  $this->senders[$usrId] = $sender;
63 
64  return $sender;
65  }
66 
67  public function system(): ilMailMimeSenderSystem
68  {
69  return new ilMailMimeSenderSystem($this->settings);
70  }
71 
72  public function user(int $usrId): ilMailMimeSenderUser
73  {
74  return new ilMailMimeSenderUserById($this->settings, $usrId);
75  }
76 
77  public function userByEmailAddress(string $emailAddress): ilMailMimeSenderUser
78  {
79  return new ilMailMimeSenderUserByEmailAddress($this->settings, $emailAddress);
80  }
81 }
Class ilMailMimeSenderFactory.
const ANONYMOUS_USER_ID
Definition: constants.php:27
__construct(ilSetting $settings, int $anonymousUsrId=null)
Class ilMailMimeSenderSystem.
Class ilMailMimeSenderUserByEmailAddress.
Class ilMailMimeSenderSystem.
Interface ilMailMimeTransport.
userByEmailAddress(string $emailAddress)
Class ilMailMimeSenderUserById.