ILIAS  release_8 Revision v8.24
class.ilMailTemplatePlaceholderResolver.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
28 protected string $message = '';
29
30 public function __construct(ilMailTemplateContext $context, string $a_message)
31 {
32 $this->context = $context;
33 $this->message = $a_message;
34 }
35
36 public function resolve(
37 ilObjUser $user = null,
38 array $contextParameters = [],
39 bool $replaceEmptyPlaceholders = true
40 ): string {
41 $message = $this->message;
42
43 foreach ($this->context->getPlaceholders() as $key => $ph_definition) {
44 $result = $this->context->resolvePlaceholder($key, $contextParameters, $user);
45 if (!$replaceEmptyPlaceholders && $result === '') {
46 continue;
47 }
48
49 $startTag = '\[IF_' . strtoupper($key) . '\]';
50 $endTag = '\[\/IF_' . strtoupper($key) . '\]';
51
52 if ($result !== '') {
53 $message = str_replace('[' . $ph_definition['placeholder'] . ']', $result, $message);
54
55 if (array_key_exists('supportsCondition', $ph_definition) &&
56 $ph_definition['supportsCondition']
57 ) {
58 $message = preg_replace(
59 '/' . $startTag . '(.*?)' . $endTag . '/imsU',
60 '$1',
62 );
63 }
64 } else {
65 $message = preg_replace(
66 '/[[:space:]]\[' . $ph_definition['placeholder'] . '\][[:space:]]/ims',
67 ' ',
69 );
70 $message = preg_replace(
71 '/\[' . $ph_definition['placeholder'] . '\]/ims',
72 '',
74 );
75
76 if (array_key_exists('supportsCondition', $ph_definition) &&
77 $ph_definition['supportsCondition']
78 ) {
79 $message = preg_replace(
80 '/' . $startTag . '.*?' . $endTag . '/imsU',
81 '',
83 );
84 }
85 }
86 }
87
88 return $message;
89 }
90}
Class ilMailTemplateContext.
resolve(ilObjUser $user=null, array $contextParameters=[], bool $replaceEmptyPlaceholders=true)
__construct(ilMailTemplateContext $context, string $a_message)
User class.
string $key
Consumer key/client ID value.
Definition: System.php:193