‪TYPO3CMS  ‪main
IdentifierTokenStream.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 
44 {
45  private bool ‪$relative = false;
46 
52  public function ‪__toString(): string
53  {
54  $source = [];
55  $this->‪reset();
56  while ($token = $this->‪getNext()) {
57  $source[] = (string)$token;
58  }
59  $source = implode('.', $source);
60  if ($this->relative) {
61  $source = '.' . $source;
62  }
63  return $source;
64  }
65 
66  protected function ‪serialize(): array
67  {
68  $result = parent::serialize();
69  if ($this->‪isRelative()) {
70  $result['relative'] = true;
71  }
72  return $result;
73  }
74 
78  public function ‪append(‪TokenInterface $token): self
79  {
80  if ($token->‪getType() !== TokenType::T_IDENTIFIER) {
81  throw new \LogicException(
82  'Trying to add a token of type TokenType::' . $token->‪getType()->name . ' to class TokenStreamIdentifier, but only TokenType::T_IDENTIFIERS are allowed.',
83  1655138907
84  );
85  }
86  $this->tokens[] = $token;
87  return $this;
88  }
89 
93  public function ‪setRelative(): self
94  {
95  $this->relative = true;
96  return $this;
97  }
98 
102  public function ‪isRelative(): bool
103  {
104  return ‪$this->relative;
105  }
106 }
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\IdentifierTokenStream\setRelative
‪setRelative()
Definition: IdentifierTokenStream.php:93
‪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\IdentifierTokenStream\serialize
‪serialize()
Definition: IdentifierTokenStream.php:66
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\IdentifierTokenStream
Definition: IdentifierTokenStream.php:44
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\IdentifierTokenStream\$relative
‪bool $relative
Definition: IdentifierTokenStream.php:45
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\TokenInterface\getType
‪getType()
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream
Definition: AbstractTokenStream.php:26
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\TokenInterface
Definition: TokenInterface.php:62
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\IdentifierTokenStream\append
‪append(TokenInterface $token)
Definition: IdentifierTokenStream.php:78
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\getNext
‪getNext()
Definition: AbstractTokenStream.php:92
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\IdentifierTokenStream\__toString
‪__toString()
Definition: IdentifierTokenStream.php:52
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\IdentifierTokenStream\isRelative
‪isRelative()
Definition: IdentifierTokenStream.php:102