ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMailTemplateContextAdapter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 {
33  protected array $contexts = [];
34  protected array $context_parameter = [];
35  protected ?ilObjUser $recipient = null;
36 
37  public function __construct(
38  array $contexts,
39  array $context_parameters,
40  private readonly Mustache_Engine $mustache_engine,
41  ilObjUser $recipient = null
42  ) {
43  $this->contexts = $contexts;
44  $this->context_parameter = $context_parameters;
45  $this->recipient = $recipient;
46  }
47 
49  {
50  $clone = clone $this;
51  $clone->contexts[] = $context;
52  return $clone;
53  }
54 
55  public function __isset(string $name): bool
56  {
57  foreach ($this->contexts as $context) {
58  $possible_placeholder = array_map(
59  static function ($placeholder): string {
60  return strtoupper($placeholder);
61  },
62  array_keys($context->getPlaceholders())
63  );
64  if (in_array($name, $possible_placeholder, true)) {
65  return true;
66  }
67  }
68 
69  return false;
70  }
71 
72  public function __get(string $name): string
73  {
74  foreach ($this->contexts as $context) {
75  $ret = $context->resolvePlaceholder($name, $this->context_parameter, $this->recipient);
76  if (in_array($name, $context->getNestedPlaceholders(), true)) {
77  $ret = $this->mustache_engine->render($ret, $this);
78  }
79  if ($ret !== '') {
80  return $ret;
81  }
82  }
83 
84  return '';
85  }
86 }
__construct(array $contexts, array $context_parameters, private readonly Mustache_Engine $mustache_engine, ilObjUser $recipient=null)
$context
Definition: webdav.php:31
This class forms an interface between the existing ILIAS mail contexts and the requirements of Mustac...
Class ilMailTemplateContext.
withContext(ilMailTemplateContext $context)