‪TYPO3CMS  ‪main
AbstractTokenStream.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 
26 {
30  protected array ‪$tokens = [];
31  protected int ‪$currentIndex = -1;
32 
36  public function ‪__toString(): string
37  {
38  $source = '';
39  $this->‪reset();
40  while ($token = $this->‪getNext()) {
41  $source .= $token;
42  }
43  return $source;
44  }
45 
51  final public function ‪__serialize(): array
52  {
53  return $this->‪serialize();
54  }
55 
56  protected function ‪serialize(): array
57  {
58  $result['tokens'] = ‪$this->tokens;
59  return $result;
60  }
61 
65  public function ‪append(‪TokenInterface $token): self
66  {
67  $this->tokens[] = $token;
68  return $this;
69  }
70 
75  public function ‪isEmpty(): bool
76  {
77  return empty($this->tokens);
78  }
79 
83  public function ‪reset(): static
84  {
85  $this->currentIndex = -1;
86  return $this;
87  }
88 
92  public function ‪getNext(): ?‪TokenInterface
93  {
94  $this->currentIndex++;
95  return $this->tokens[‪$this->currentIndex] ?? null;
96  }
97 
98  public function ‪peekNext(): ?‪TokenInterface
99  {
100  return $this->tokens[$this->currentIndex + 1] ?? null;
101  }
102 
103  public function ‪getAll(): array
104  {
105  return ‪$this->tokens;
106  }
107 
108  public function ‪setAll(array ‪$tokens): self
109  {
110  $this->tokens = ‪$tokens;
111  return $this;
112  }
113 }
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\__toString
‪__toString()
Definition: AbstractTokenStream.php:36
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\isEmpty
‪isEmpty()
Definition: AbstractTokenStream.php:75
‪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\AbstractTokenStream\serialize
‪serialize()
Definition: AbstractTokenStream.php:56
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\$currentIndex
‪int $currentIndex
Definition: AbstractTokenStream.php:31
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\getAll
‪getAll()
Definition: AbstractTokenStream.php:103
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\$tokens
‪array $tokens
Definition: AbstractTokenStream.php:30
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\TokenStreamInterface
Definition: TokenStreamInterface.php:30
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\append
‪append(TokenInterface $token)
Definition: AbstractTokenStream.php:65
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream
Definition: AbstractTokenStream.php:26
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\__serialize
‪__serialize()
Definition: AbstractTokenStream.php:51
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\TokenInterface
Definition: TokenInterface.php:62
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\getNext
‪getNext()
Definition: AbstractTokenStream.php:92
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\peekNext
‪peekNext()
Definition: AbstractTokenStream.php:98
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\AbstractTokenStream\setAll
‪setAll(array $tokens)
Definition: AbstractTokenStream.php:108