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