‪TYPO3CMS  ‪main
ConstantAwareTokenStream.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
29 {
30  private ?array ‪$flatConstants = null;
31 
35  public function ‪setFlatConstants(?array ‪$flatConstants = [])
36  {
37  $this->flatConstants = ‪$flatConstants;
38  }
39 
44  public function ‪__toString(): string
45  {
46  $source = '';
47  $this->‪reset();
48  while ($token = $this->‪getNext()) {
49  if ($token->getType() === TokenType::T_CONSTANT) {
50  $tokenValue = ltrim(ltrim(rtrim($token->getValue(), '}'), '{'), '$');
51  if (is_array($this->flatConstants) && array_key_exists($tokenValue, $this->flatConstants)) {
52  $source .= $this->flatConstants[$tokenValue];
53  continue;
54  }
55  }
56  $source .= $token;
57  }
58  $this->‪reset();
59  return $source;
60  }
61 }
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\reset
‪reset()
Definition: AbstractTokenStream.php:83
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token
Definition: AbstractToken.php:18
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\ConstantAwareTokenStream\__toString
‪__toString()
Definition: ConstantAwareTokenStream.php:44
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\ConstantAwareTokenStream\setFlatConstants
‪setFlatConstants(?array $flatConstants=[])
Definition: ConstantAwareTokenStream.php:35
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream
Definition: AbstractTokenStream.php:26
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\ConstantAwareTokenStream
Definition: ConstantAwareTokenStream.php:29
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\getNext
‪getNext()
Definition: AbstractTokenStream.php:92
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\ConstantAwareTokenStream\$flatConstants
‪array $flatConstants
Definition: ConstantAwareTokenStream.php:30