‪TYPO3CMS  ‪main
AbstractInclude.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 
22 
28 abstract class ‪AbstractInclude implements ‪IncludeInterface
29 {
30  private ?string ‪$identifier = null;
31  protected string ‪$name = '';
32  protected string ‪$path = '';
33 
37  protected array ‪$children = [];
38  protected ?‪LineStream ‪$lineStream = null;
40  protected bool ‪$isSplit = false;
41  protected bool ‪$root = false;
42  protected bool ‪$clear = false;
43  protected ?int ‪$pid = null;
44 
50  final public function ‪__serialize(): array
51  {
52  return $this->‪serialize();
53  }
54 
55  protected function ‪serialize(): array
56  {
57  $result['children'] = ‪$this->children;
58  if ($this->‪isSplit()) {
59  $result['isSplit'] = true;
60  }
61  if (!$this->‪isSplit()) {
62  $result['lineStream'] = ‪$this->lineStream;
63  }
64  if ($this->‪isRoot()) {
65  $result['root'] = true;
66  }
67  if ($this->‪isClear()) {
68  $result['clear'] = true;
69  }
70  return $result;
71  }
72 
73  public function ‪getType(): string
74  {
75  $classWithNamespace = static::class;
76  $lastBackslash = strrpos($classWithNamespace, '\\');
77  return substr($classWithNamespace, $lastBackslash + 1, -7);
78  }
79 
80  public function ‪setIdentifier(string ‪$identifier): void
81  {
82  $this->identifier = hash('xxh3', ‪$identifier);
83  $childCounter = 0;
84  foreach ($this->‪getNextChild() as $child) {
85  $child->setIdentifier($this->identifier . $childCounter);
86  $childCounter++;
87  }
88  }
89 
90  public function ‪getIdentifier(): string
91  {
92  if ($this->identifier === null) {
93  throw new \RuntimeException(
94  'Identifier has not been initialized. This happens when getIdentifier() is called on'
95  . ' trees retrieved from cache. The identifier is not supposed to be used in this context.',
96  1673634853
97  );
98  }
99  return ‪$this->identifier;
100  }
101 
102  public function ‪setName(string ‪$name): void
103  {
104  $this->name = ‪$name;
105  }
106 
107  public function ‪getName(): string
108  {
109  return ‪$this->name;
110  }
111 
112  public function ‪setPath(string ‪$path): void
113  {
114  $this->path = ‪$path;
115  }
116 
117  public function ‪getPath(): string
118  {
119  return ‪$this->path;
120  }
121 
122  public function ‪addChild(‪IncludeInterface $node): void
123  {
124  $this->children[] = $node;
125  }
126 
127  public function ‪hasChildren(): bool
128  {
129  return !empty($this->children);
130  }
131 
132  public function ‪getNextChild(): iterable
133  {
134  foreach ($this->children as $child) {
135  yield $child;
136  }
137  }
138 
139  public function ‪isSysTemplateRecord(): bool
140  {
141  return false;
142  }
143 
145  {
146  $this->lineStream = ‪$lineStream;
147  }
148 
149  public function ‪getLineStream(): ?‪LineStream
150  {
151  return ‪$this->lineStream;
152  }
153 
154  public function ‪setOriginalLine(‪LineInterface $line): void
155  {
156  $this->originalTokenLine = $line;
157  }
158 
160  {
162  }
163 
164  public function ‪setSplit(): void
165  {
166  $this->‪isSplit = true;
167  }
168 
169  public function ‪isSplit(): bool
170  {
171  return ‪$this->isSplit;
172  }
173 
174  public function ‪setRoot(bool ‪$root): void
175  {
176  $this->root = ‪$root;
177  }
178 
179  public function ‪isRoot(): bool
180  {
181  return ‪$this->root;
182  }
183 
184  public function ‪setClear(bool ‪$clear): void
185  {
186  $this->clear = ‪$clear;
187  }
188 
189  public function ‪isClear(): bool
190  {
191  return ‪$this->clear;
192  }
193 
194  public function ‪setPid(int ‪$pid): void
195  {
196  $this->pid = ‪$pid;
197  }
198 
199  public function ‪getPid(): ?int
200  {
201  return ‪$this->pid;
202  }
203 }
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\serialize
‪serialize()
Definition: AbstractInclude.php:55
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineInterface
Definition: LineInterface.php:32
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\hasChildren
‪hasChildren()
Definition: AbstractInclude.php:127
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\isRoot
‪isRoot()
Definition: AbstractInclude.php:179
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\getName
‪getName()
Definition: AbstractInclude.php:107
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\isClear
‪isClear()
Definition: AbstractInclude.php:189
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setRoot
‪setRoot(bool $root)
Definition: AbstractInclude.php:174
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setOriginalLine
‪setOriginalLine(LineInterface $line)
Definition: AbstractInclude.php:154
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\isSplit
‪isSplit()
Definition: AbstractInclude.php:169
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$root
‪bool $root
Definition: AbstractInclude.php:41
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setName
‪setName(string $name)
Definition: AbstractInclude.php:102
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$identifier
‪string $identifier
Definition: AbstractInclude.php:30
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\getPid
‪getPid()
Definition: AbstractInclude.php:199
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setPid
‪setPid(int $pid)
Definition: AbstractInclude.php:194
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$clear
‪bool $clear
Definition: AbstractInclude.php:42
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setLineStream
‪setLineStream(?LineStream $lineStream)
Definition: AbstractInclude.php:144
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$children
‪array $children
Definition: AbstractInclude.php:37
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$lineStream
‪LineStream $lineStream
Definition: AbstractInclude.php:38
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface
Definition: IncludeInterface.php:39
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$path
‪string $path
Definition: AbstractInclude.php:32
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$originalTokenLine
‪LineInterface $originalTokenLine
Definition: AbstractInclude.php:39
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\isSysTemplateRecord
‪isSysTemplateRecord()
Definition: AbstractInclude.php:139
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\__serialize
‪__serialize()
Definition: AbstractInclude.php:50
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\getIdentifier
‪getIdentifier()
Definition: AbstractInclude.php:90
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\getLineStream
‪getLineStream()
Definition: AbstractInclude.php:149
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude
Definition: AbstractInclude.php:29
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\getPath
‪getPath()
Definition: AbstractInclude.php:117
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\addChild
‪addChild(IncludeInterface $node)
Definition: AbstractInclude.php:122
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\getOriginalLine
‪getOriginalLine()
Definition: AbstractInclude.php:159
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setPath
‪setPath(string $path)
Definition: AbstractInclude.php:112
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$isSplit
‪bool $isSplit
Definition: AbstractInclude.php:40
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setIdentifier
‪setIdentifier(string $identifier)
Definition: AbstractInclude.php:80
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode
Definition: AbstractConditionInclude.php:18
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$name
‪string $name
Definition: AbstractInclude.php:31
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\getNextChild
‪getNextChild()
Definition: AbstractInclude.php:132
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\$pid
‪int $pid
Definition: AbstractInclude.php:43
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\getType
‪getType()
Definition: AbstractInclude.php:73
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Line\LineStream
Definition: LineStream.php:29
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setClear
‪setClear(bool $clear)
Definition: AbstractInclude.php:184
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AbstractInclude\setSplit
‪setSplit()
Definition: AbstractInclude.php:164