‪TYPO3CMS  ‪main
IncludeTreeSourceAggregatorVisitor.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 
36 {
40  private string ‪$source = '';
41 
48  private string ‪$startNodeIdentifier = '';
49  private bool ‪$startNodeHandled = false;
50  private int ‪$startNodeDepth = 0;
51  private bool ‪$isWithinStartNode = false;
52 
54  {
55  $this->startNodeIdentifier = ‪$startNodeIdentifier;
56  }
57 
58  public function ‪getSource(): string
59  {
60  return ‪$this->source;
61  }
62 
63  public function ‪visitBeforeChildren(‪IncludeInterface $include, int $currentDepth): void
64  {
65  if ($this->startNodeHandled && $currentDepth <= $this->startNodeDepth) {
66  $this->isWithinStartNode = false;
67  }
68  if ($this->startNodeIdentifier === $include->‪getIdentifier() && !$this->startNodeHandled) {
69  $this->startNodeDepth = $currentDepth;
70  $this->isWithinStartNode = true;
71  $this->startNodeHandled = true;
72  }
73  if (empty($this->startNodeIdentifier) || $this->isWithinStartNode) {
74  $lineStream = $include->‪getLineStream();
75  if ($lineStream !== null
76  && !$lineStream->isEmpty()
77  && ($include instanceof ‪ConditionInclude || $include instanceof ‪ConditionElseInclude)
78  ) {
79  $this->source .= "\n#\n# Condition from '" . $include->‪getName() . '\' Line ' . $include->getConditionToken()->getLine() . "\n#\n";
80  $this->source .= $lineStream;
81  }
82  if ($include instanceof IncludeTyposcriptInclude || $include instanceof AtImportInclude) {
83  $this->source .= "\n#\n# Include from definition '" . trim((string)($include->getOriginalLine()->getTokenStream())) . "'\n#\n";
84  }
85  }
86  }
87 
88  public function visit(IncludeInterface $include, int $currentDepth): void
89  {
90  if (empty($this->startNodeIdentifier) || $this->isWithinStartNode) {
91  $lineStream = $include->getLineStream();
92  if ($lineStream === null
93  || $lineStream->isEmpty()
94  || ($include->isSplit())
95  ) {
96  return;
97  }
98  $this->source .= "\n#\n# Content from '" . $include->getName() . "'\n#\n";
99  $this->source .= $lineStream;
100  }
101  }
102 }
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\getName
‪getName()
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor\setStartNodeIdentifier
‪setStartNodeIdentifier(string $startNodeIdentifier)
Definition: IncludeTreeSourceAggregatorVisitor.php:53
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor\$source
‪string $source
Definition: IncludeTreeSourceAggregatorVisitor.php:40
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeVisitorInterface
Definition: IncludeTreeVisitorInterface.php:28
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface
Definition: IncludeInterface.php:39
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor\$startNodeDepth
‪int $startNodeDepth
Definition: IncludeTreeSourceAggregatorVisitor.php:50
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor
Definition: IncludeTreeSourceAggregatorVisitor.php:36
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor\$isWithinStartNode
‪bool $isWithinStartNode
Definition: IncludeTreeSourceAggregatorVisitor.php:51
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor\$startNodeIdentifier
‪string $startNodeIdentifier
Definition: IncludeTreeSourceAggregatorVisitor.php:48
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor\$startNodeHandled
‪bool $startNodeHandled
Definition: IncludeTreeSourceAggregatorVisitor.php:49
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\ConditionInclude
Definition: ConditionInclude.php:29
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeTyposcriptInclude
Definition: IncludeTyposcriptInclude.php:25
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor\getSource
‪getSource()
Definition: IncludeTreeSourceAggregatorVisitor.php:58
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\getLineStream
‪getLineStream()
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSourceAggregatorVisitor\visitBeforeChildren
‪visitBeforeChildren(IncludeInterface $include, int $currentDepth)
Definition: IncludeTreeSourceAggregatorVisitor.php:63
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\getIdentifier
‪getIdentifier()
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor
Definition: IncludeTreeAstBuilderVisitor.php:18
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\ConditionElseInclude
Definition: ConditionElseInclude.php:34
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AtImportInclude
Definition: AtImportInclude.php:27