‪TYPO3CMS  ‪main
LineStream.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 
28 final class ‪LineStream
29 {
33  private array ‪$lines = [];
34  protected int ‪$currentIndex = -1;
35 
40  public function ‪__toString(): string
41  {
42  $source = '';
43  foreach ($this->‪getNextLine() as $line) {
44  // We do *not* implement __toString() on lines since this is a
45  // backend thing only, and we do not want to accidentally stringify
46  // lines based on the full stream anywhere.
47  $source .= $line->getTokenStream()->reset();
48  }
49  return $source;
50  }
51 
57  final public function ‪__serialize(): array
58  {
59  return [
60  'lines' => ‪$this->lines,
61  ];
62  }
63 
67  public function ‪append(‪LineInterface $line): self
68  {
69  $this->lines[] = $line;
70  return $this;
71  }
72 
77  public function ‪isEmpty(): bool
78  {
79  return empty($this->lines);
80  }
81 
85  public function ‪getNextLine(): iterable
86  {
87  foreach ($this->lines as $child) {
88  yield $child;
89  }
90  }
91 
95  public function ‪reset(): self
96  {
97  $this->currentIndex = -1;
98  return $this;
99  }
100 
111  public function ‪getNext(): ?‪LineInterface
112  {
113  $this->currentIndex++;
114  return $this->lines[‪$this->currentIndex] ?? null;
115  }
116 
120  public function ‪peekNext(): ?‪LineInterface
121  {
122  return $this->lines[$this->currentIndex + 1] ?? null;
123  }
124 }
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineInterface
Definition: LineInterface.php:32
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line
Definition: AbstractLine.php:18
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\reset
‪reset()
Definition: LineStream.php:95
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\peekNext
‪peekNext()
Definition: LineStream.php:120
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\$lines
‪array $lines
Definition: LineStream.php:33
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\getNext
‪getNext()
Definition: LineStream.php:111
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\isEmpty
‪isEmpty()
Definition: LineStream.php:77
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\$currentIndex
‪int $currentIndex
Definition: LineStream.php:34
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\getNextLine
‪iterable< LineInterface > getNextLine()
Definition: LineStream.php:85
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\append
‪append(LineInterface $line)
Definition: LineStream.php:67
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\__serialize
‪__serialize()
Definition: LineStream.php:57
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream
Definition: LineStream.php:29
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream\__toString
‪__toString()
Definition: LineStream.php:40