‪TYPO3CMS  ‪main
RootNode.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 
25 final class ‪RootNode extends ‪AbstractNode
26 {
31  public function ‪__clone(): void
32  {
33  throw new \LogicException('Can not clone RootNode', 1655988945);
34  }
35 
39  protected function ‪serialize(): array
40  {
41  return [
42  'children' => ‪$this->children,
43  ];
44  }
45 
46  public function ‪getName(): ?string
47  {
48  return null;
49  }
50 
51  public function ‪updateName(string ‪$name): void
52  {
53  throw new \RuntimeException('RootNode has no name. Don\'t call updateName().', 1653743453);
54  }
55 
56  public function ‪setValue(?string ‪$value): void
57  {
58  throw new \RuntimeException('RootNode has no value. Don\'t call setValue().', 1653743454);
59  }
60 
61  public function ‪appendValue(string ‪$value): void
62  {
63  throw new \RuntimeException('RootNode has no value. Don\'t call appendValue().', 1653743455);
64  }
65 
66  public function ‪getValue(): ?string
67  {
68  return null;
69  }
70 
71  public function ‪isValueNull(): bool
72  {
73  return true;
74  }
75 
79  public function ‪toArray(): array
80  {
81  ‪$result = [];
82  foreach ($this->‪getNextChild() as $child) {
83  $childName = $child->getName();
84  if ($child instanceof ‪ReferenceChildNode) {
85  // Hack for b/w compat parsing of `=<` operator. See ContentObjectRenderer cObjGetSingle() and mergeTSRef()
86  $childValue = '< ' . $child->getReferenceSourceStream();
87  } else {
88  $childValue = $child->getValue();
89  }
90  if ($childValue !== null) {
91  ‪$result[$childName] = $childValue;
92  }
93  ‪$grandChildren = $child->toArray();
94  if (‪$grandChildren !== null) {
95  ‪$result[$childName . '.'] = ‪$grandChildren;
96  }
97  }
98  return ‪$result;
99  }
100 
101  public function ‪flatten(string $prefix = ''): array
102  {
103  $flatArray = [];
104  foreach ($this->‪getNextChild() as $child) {
105  $flatArray = array_merge($flatArray, $child->flatten(''));
106  }
107  return $flatArray;
108  }
109 }
‪TYPO3\CMS\Core\TypoScript\AST\Node\AbstractNode\getNextChild
‪getNextChild()
Definition: AbstractNode.php:121
‪TYPO3\CMS\Core\TypoScript\AST\Node\AbstractNode\$children
‪array $children
Definition: AbstractNode.php:38
‪TYPO3\CMS\Core\TypoScript\AST\Node\ReferenceChildNode
Definition: ReferenceChildNode.php:39
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\setValue
‪setValue(?string $value)
Definition: RootNode.php:56
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\getName
‪getName()
Definition: RootNode.php:46
‪TYPO3\CMS\Core\TypoScript\AST\Node\AbstractNode\$name
‪string $name
Definition: AbstractNode.php:31
‪TYPO3\CMS\Core\TypoScript\AST\Node\NodeInterface\toArray
‪toArray()
‪TYPO3\CMS\Core\TypoScript\AST\Node\AbstractNode\$value
‪string $value
Definition: AbstractNode.php:32
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\$result
‪if($grandChildren !==null) return $result
Definition: RootNode.php:94
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\getValue
‪getValue()
Definition: RootNode.php:66
‪TYPO3\CMS\Core\TypoScript\AST\Node\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\__clone
‪__clone()
Definition: RootNode.php:31
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\$grandChildren
‪if($childValue !==null) $grandChildren
Definition: RootNode.php:93
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\updateName
‪updateName(string $name)
Definition: RootNode.php:51
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\serialize
‪serialize()
Definition: RootNode.php:39
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode
Definition: RootNode.php:26
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\isValueNull
‪isValueNull()
Definition: RootNode.php:71
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\flatten
‪flatten(string $prefix='')
Definition: RootNode.php:101
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode\appendValue
‪appendValue(string $value)
Definition: RootNode.php:61
‪TYPO3\CMS\Core\TypoScript\AST\Node
Definition: AbstractChildNode.php:18