‪TYPO3CMS  ‪main
ConditionVerdictAwareIncludeTreeTraverser.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 
38 {
39  public function ‪traverse(‪RootInclude $rootInclude, array $visitors): void
40  {
41  foreach ($visitors as $visitor) {
42  if (!$visitor instanceof ‪IncludeTreeVisitorInterface) {
43  throw new \RuntimeException(
44  'Visitors must implement IncludeTreeVisitorInterface',
45  1689244840
46  );
47  }
48  }
49  $this->‪traverseRecursive($rootInclude, $visitors, 0);
50  }
51 
52  private function ‪traverseRecursive(‪IncludeInterface $include, array $visitors, int $currentDepth): void
53  {
54  foreach ($visitors as $visitor) {
55  $visitor->visitBeforeChildren($include, $currentDepth);
56  }
57  if ($include instanceof ‪IncludeConditionInterface && !$include->getConditionVerdict()) {
58  // Don't traverse children if condition did not match.
59  return;
60  }
61  foreach ($include->‪getNextChild() as $child) {
62  $this->‪traverseRecursive($child, $visitors, $currentDepth + 1);
63  foreach ($visitors as $visitor) {
64  $visitor->visit($child, $currentDepth);
65  }
66  }
67  }
68 }
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\ConditionVerdictAwareIncludeTreeTraverser\traverse
‪traverse(RootInclude $rootInclude, array $visitors)
Definition: ConditionVerdictAwareIncludeTreeTraverser.php:39
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\IncludeTreeTraverserInterface
Definition: IncludeTreeTraverserInterface.php:31
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeVisitorInterface
Definition: IncludeTreeVisitorInterface.php:28
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface\getNextChild
‪iterable< IncludeInterface > getNextChild()
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeConditionInterface
Definition: IncludeConditionInterface.php:32
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface
Definition: IncludeInterface.php:39
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\ConditionVerdictAwareIncludeTreeTraverser
Definition: ConditionVerdictAwareIncludeTreeTraverser.php:38
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\RootInclude
Definition: RootInclude.php:27
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\ConditionVerdictAwareIncludeTreeTraverser\traverseRecursive
‪traverseRecursive(IncludeInterface $include, array $visitors, int $currentDepth)
Definition: ConditionVerdictAwareIncludeTreeTraverser.php:52
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser
Definition: ConditionVerdictAwareIncludeTreeTraverser.php:18