ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
MailTemplateContextAdapter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ilObjUser;
25
36{
37 public function __construct(
39 protected array $contexts,
40 protected array $context_parameter,
41 protected readonly TemplateEngineInterface $template_engine,
42 protected ?ilObjUser $recipient = null
43 ) {
44 }
45
46 public function withContext(ilMailTemplateContext $context): self
47 {
48 $clone = clone $this;
49 $clone->contexts[] = $context;
50 return $clone;
51 }
52
53 public function __isset(string $name): bool
54 {
55 foreach ($this->contexts as $context) {
56 $possible_placeholder = array_map(
57 static function ($placeholder): string {
58 return strtoupper($placeholder);
59 },
60 array_keys($context->getPlaceholders())
61 );
62 if (\in_array($name, $possible_placeholder, true)) {
63 return true;
64 }
65 }
66
67 return false;
68 }
69
70 public function __get(string $name): string
71 {
72 foreach ($this->contexts as $context) {
73 $ret = $context->resolvePlaceholder($name, $this->context_parameter, $this->recipient);
74 if (\in_array($name, $context->getNestedPlaceholders(), true)) {
75 $ret = $this->template_engine->render($ret, $this);
76 }
77 if ($ret !== '') {
78 return $ret;
79 }
80 }
81
82 return '';
83 }
84}
This class forms an interface between the existing ILIAS mail contexts and the requirements of the te...
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
User class.
Interface for template engine functionality used in Mail and related components.