‪TYPO3CMS  ‪main
IncludeTreeAstBuilderVisitor.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 
24 
39 {
41 
45  private array ‪$flatConstants = [];
46 
47  public function ‪__construct(private readonly ‪AstBuilderInterface $astBuilder)
48  {
49  $this->ast = new ‪RootNode();
50  }
51 
58  public function ‪setFlatConstants(array ‪$flatConstants)
59  {
60  $this->flatConstants = ‪$flatConstants;
61  }
62 
63  public function ‪getAst(): ‪RootNode
64  {
65  return ‪$this->ast;
66  }
67 
72  public function ‪visitBeforeChildren(‪IncludeInterface $include, int $currentDepth): void
73  {
74  if ($include instanceof ‪SysTemplateInclude && $include->‪isClear()) {
75  // Reset any given AST if this sys_template row has clear flag (constants or setup clear) set.
76  $this->ast = new ‪RootNode();
77  }
78  }
79 
83  public function ‪visit(‪IncludeInterface $include, int $currentDepth): void
84  {
85  $lineStream = $include->‪getLineStream();
86  if ($lineStream && !$include->‪isSplit()) {
87  // A "split" include means that the entire TypoScript is split into child includes. The
88  // TokenStream of the split include itself must not be parsed, so it's excluded here.
89  $this->ast = $this->astBuilder->build($lineStream, $this->ast, $this->flatConstants);
90  }
91  }
92 }
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor\__construct
‪__construct(private readonly AstBuilderInterface $astBuilder)
Definition: IncludeTreeAstBuilderVisitor.php:47
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor\visitBeforeChildren
‪visitBeforeChildren(IncludeInterface $include, int $currentDepth)
Definition: IncludeTreeAstBuilderVisitor.php:72
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor
Definition: IncludeTreeAstBuilderVisitor.php:39
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeVisitorInterface
Definition: IncludeTreeVisitorInterface.php:28
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor\setFlatConstants
‪setFlatConstants(array $flatConstants)
Definition: IncludeTreeAstBuilderVisitor.php:58
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface
Definition: IncludeInterface.php:39
‪TYPO3\CMS\Core\TypoScript\AST\AstBuilderInterface
Definition: AstBuilderInterface.php:34
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\isSplit
‪isSplit()
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode
Definition: RootNode.php:26
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor\getAst
‪getAst()
Definition: IncludeTreeAstBuilderVisitor.php:63
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\isClear
‪isClear()
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\getLineStream
‪getLineStream()
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor\visit
‪visit(IncludeInterface $include, int $currentDepth)
Definition: IncludeTreeAstBuilderVisitor.php:83
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor
Definition: IncludeTreeAstBuilderVisitor.php:18
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\SysTemplateInclude
Definition: SysTemplateInclude.php:26
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor\$ast
‪RootNode $ast
Definition: IncludeTreeAstBuilderVisitor.php:40
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor\$flatConstants
‪array $flatConstants
Definition: IncludeTreeAstBuilderVisitor.php:45