ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SubstitutionResultResolver.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
30{
31 private \ilLanguage $lng;
32
33 public function __construct(
34 private FieldSubstitution $substitution,
35 ) {
36 global $DIC;
37 $this->lng = $DIC->language();
38 }
39
40 public function resolve(Token $token): Result
41 {
42 // Token is a string, either a field placeholder [[Field name]] or a string starting with "
43 $token_value = $token->getValue();
44 if (str_starts_with($token_value, '"')) { // this is a "simple" string
45 return new StringResult(strip_tags(trim($token_value, '"')));
46 }
47
48 if (str_starts_with($token_value, Tokenizer::FIELD_OPENER)) { // this is a field placeholder
49 return new StringResult(trim(strip_tags($this->substitution->substituteFieldValue($token_value))));
50 }
51
52 throw new \ilException("Unrecognized string token: '$token_value'");
53 }
54}
Token
The string representation of these tokens must not occur in the names of metadata elements.
Definition: Token.php:28
global $DIC
Definition: shib_login.php:26
$token
Definition: xapitoken.php:70