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