‪TYPO3CMS  ‪main
SetupConfigMerger.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 
34 final readonly class ‪SetupConfigMerger
35 {
36  public function ‪merge(?‪ChildNodeInterface $config, ?‪ChildNodeInterface $pageConfig): ‪RootNode
37  {
38  $configResult = new ‪RootNode();
39  if ($config) {
40  foreach ($config->‪getNextChild() as $child) {
41  $configResult->addChild($child);
42  }
43  }
44  if (!$pageConfig) {
45  return $configResult;
46  }
47  $this->‪mergeRecursive($pageConfig, $configResult);
48  return $configResult;
49  }
50 
51  private function ‪mergeRecursive(‪ChildNodeInterface $mergeFrom, ‪NodeInterface $mergeTo): void
52  {
53  foreach ($mergeFrom->‪getNextChild() as $mergeFromChild) {
54  $mergeToChild = $mergeTo->‪getChildByName($mergeFromChild->getName());
55  if (!$mergeToChild) {
56  $mergeTo->‪addChild($mergeFromChild);
57  continue;
58  }
59  $mergeFromChildValue = $mergeFromChild->getValue();
60  if ($mergeFromChildValue !== null && $mergeFromChildValue !== $mergeToChild->getValue()) {
61  $mergeToChild->setValue($mergeFromChildValue);
62  }
63  $this->‪mergeRecursive($mergeFromChild, $mergeToChild);
64  }
65  }
66 }
‪TYPO3\CMS\Core\TypoScript\AST\Merger\SetupConfigMerger
Definition: SetupConfigMerger.php:35
‪TYPO3\CMS\Core\TypoScript\AST\Merger\SetupConfigMerger\mergeRecursive
‪mergeRecursive(ChildNodeInterface $mergeFrom, NodeInterface $mergeTo)
Definition: SetupConfigMerger.php:51
‪TYPO3\CMS\Core\TypoScript\AST\Merger
Definition: SetupConfigMerger.php:18
‪TYPO3\CMS\Core\TypoScript\AST\Node\NodeInterface\getNextChild
‪iterable< ChildNodeInterface > getNextChild()
‪TYPO3\CMS\Core\TypoScript\AST\Node\NodeInterface
Definition: NodeInterface.php:35
‪TYPO3\CMS\Core\TypoScript\AST\Node\ChildNodeInterface
Definition: ChildNodeInterface.php:26
‪TYPO3\CMS\Core\TypoScript\AST\Merger\SetupConfigMerger\merge
‪merge(?ChildNodeInterface $config, ?ChildNodeInterface $pageConfig)
Definition: SetupConfigMerger.php:36
‪TYPO3\CMS\Core\TypoScript\AST\Node\NodeInterface\addChild
‪addChild(ChildNodeInterface $node)
‪TYPO3\CMS\Core\TypoScript\AST\Node\NodeInterface\getChildByName
‪getChildByName(string $name)
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode
Definition: RootNode.php:26