ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SubstitutionResultResolver.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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:27
$token
Definition: xapitoken.php:70
global $DIC
Definition: shib_login.php:22