ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilMailTemplateContextAdapter Class Reference

This class forms an interface between the existing ILIAS mail contexts and the requirements of Mustache. More...

+ Collaboration diagram for ilMailTemplateContextAdapter:

Public Member Functions

 __construct (array $contexts, array $context_parameters, private readonly Mustache_Engine $mustache_engine, ilObjUser $recipient=null)
 
 withContext (ilMailTemplateContext $context)
 
 __isset (string $name)
 
 __get (string $name)
 

Protected Attributes

array $contexts = []
 
array $context_parameter = []
 
ilObjUser $recipient = null
 

Detailed Description

This class forms an interface between the existing ILIAS mail contexts and the requirements of Mustache.

In the old system, it was possible to gradually replace individual placeholders via the contexts. This is now done by Mustache and requires a single source. If a placeholder does not exist in this source, then it will be replaced with NULL. Mustache takes two steps to find the placeholder. On the one hand the check whether it would be theoretically possible and the actual query for the value if the check is successful. This is done in this class using the two magic methods. With the introduction of this interface, the ILIAS mail contexts do not have to be changed for Mustache.

Definition at line 30 of file class.ilMailTemplateContextAdapter.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateContextAdapter::__construct ( array  $contexts,
array  $context_parameters,
private readonly Mustache_Engine  $mustache_engine,
ilObjUser  $recipient = null 
)

Definition at line 37 of file class.ilMailTemplateContextAdapter.php.

References $contexts, and $recipient.

42  {
43  $this->contexts = $contexts;
44  $this->context_parameter = $context_parameters;
45  $this->recipient = $recipient;
46  }

Member Function Documentation

◆ __get()

ilMailTemplateContextAdapter::__get ( string  $name)

Definition at line 72 of file class.ilMailTemplateContextAdapter.php.

References $context.

72  : 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  }
$context
Definition: webdav.php:31

◆ __isset()

ilMailTemplateContextAdapter::__isset ( string  $name)

Definition at line 55 of file class.ilMailTemplateContextAdapter.php.

References $context.

55  : 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  }
$context
Definition: webdav.php:31

◆ withContext()

ilMailTemplateContextAdapter::withContext ( ilMailTemplateContext  $context)

Definition at line 48 of file class.ilMailTemplateContextAdapter.php.

References $context.

48  : self
49  {
50  $clone = clone $this;
51  $clone->contexts[] = $context;
52  return $clone;
53  }
$context
Definition: webdav.php:31

Field Documentation

◆ $context_parameter

array ilMailTemplateContextAdapter::$context_parameter = []
protected

Definition at line 34 of file class.ilMailTemplateContextAdapter.php.

◆ $contexts

array ilMailTemplateContextAdapter::$contexts = []
protected

Definition at line 33 of file class.ilMailTemplateContextAdapter.php.

Referenced by __construct().

◆ $recipient

ilObjUser ilMailTemplateContextAdapter::$recipient = null
protected

Definition at line 35 of file class.ilMailTemplateContextAdapter.php.

Referenced by __construct().


The documentation for this class was generated from the following file: