‪TYPO3CMS  ‪main
IncludeTreeTraverser.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 
23 
30 {
31  public function ‪traverse(‪RootInclude $rootInclude, array $visitors): void
32  {
33  foreach ($visitors as $visitor) {
34  if (!$visitor instanceof ‪IncludeTreeVisitorInterface) {
35  throw new \RuntimeException(
36  'Visitors must implement IncludeTreeVisitorInterface',
37  1689244841
38  );
39  }
40  }
41  $this->‪traverseRecursive($rootInclude, $visitors, 0);
42  }
43 
44  private function ‪traverseRecursive(‪IncludeInterface $include, array $visitors, int $currentDepth): void
45  {
46  foreach ($visitors as $visitor) {
47  $visitor->visitBeforeChildren($include, $currentDepth);
48  }
49  foreach ($include->‪getNextChild() as $child) {
50  $this->‪traverseRecursive($child, $visitors, $currentDepth + 1);
51  foreach ($visitors as $visitor) {
52  $visitor->visit($child, $currentDepth);
53  }
54  }
55  }
56 }
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\IncludeTreeTraverserInterface
Definition: IncludeTreeTraverserInterface.php:31
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\IncludeTreeTraverser\traverseRecursive
‪traverseRecursive(IncludeInterface $include, array $visitors, int $currentDepth)
Definition: IncludeTreeTraverser.php:44
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\IncludeTreeTraverser
Definition: IncludeTreeTraverser.php:30
‪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\IncludeInterface
Definition: IncludeInterface.php:39
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\IncludeTreeTraverser\traverse
‪traverse(RootInclude $rootInclude, array $visitors)
Definition: IncludeTreeTraverser.php:31
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\RootInclude
Definition: RootInclude.php:27
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser
Definition: ConditionVerdictAwareIncludeTreeTraverser.php:18