‪TYPO3CMS  10.4
EnhancerDeclaration.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 
21 {
25  private ‪$identifier;
26 
30  private ‪$configuration = [];
31 
35  private ‪$resolveArguments = [];
36 
40  private ‪$generateParameters = [];
41 
42  public static function ‪create(string ‪$identifier): self
43  {
44  return new static(‪$identifier);
45  }
46 
47  private function ‪__construct(string ‪$identifier)
48  {
49  $this->identifier = ‪$identifier;
50  }
51 
55  public function ‪getConfiguration()
56  {
58  }
59 
63  public function ‪getResolveArguments(): array
64  {
66  }
67 
71  public function ‪getGenerateParameters(): array
72  {
74  }
75 
76  public function ‪withConfiguration(array ‪$configuration, bool $merge = false): self
77  {
78  $target = clone $this;
79 
80  $target->configuration = $merge ? $this->‪applyMergedItems($this->configuration, ‪$configuration) : ‪$configuration;
81  return $target;
82  }
83 
84  public function ‪withResolveArguments(array ‪$resolveArguments, bool $merge = false): self
85  {
86  $target = clone $this;
87  $target->resolveArguments = $merge ? $this->‪applyMergedItems($this->resolveArguments, ‪$resolveArguments) : ‪$resolveArguments;
88  return $target;
89  }
90 
91  public function ‪withGenerateParameters(array ‪$generateParameters, bool $merge = false): self
92  {
93  $target = clone $this;
94  $target->generateParameters = $merge ? $this->‪applyMergedItems($this->generateParameters, ‪$generateParameters) : ‪$generateParameters;
95  return $target;
96  }
97 
98  public function ‪describe(): string
99  {
100  return ‪$this->identifier;
101  }
102 
103  private function ‪applyMergedItems(array $currentItems, array $additionalItems): array
104  {
105  if (empty($additionalItems)) {
106  return $currentItems;
107  }
108  if ($this->‪hasOnlyNumericKeys($additionalItems)) {
109  return array_merge($currentItems, $additionalItems);
110  }
111  return array_replace_recursive($currentItems, $additionalItems);
112  }
113 
114  private function ‪hasOnlyNumericKeys(array $items): bool
115  {
116  $numericItems = array_filter($items, 'is_int', ARRAY_FILTER_USE_KEY);
117  return !empty($numericItems);
118  }
119 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\$generateParameters
‪array $generateParameters
Definition: EnhancerDeclaration.php:36
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\HasResolveArguments
Definition: HasResolveArguments.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\$configuration
‪array $configuration
Definition: EnhancerDeclaration.php:28
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\$resolveArguments
‪array $resolveArguments
Definition: EnhancerDeclaration.php:32
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\HasGenerateParameters
Definition: HasGenerateParameters.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\$identifier
‪string $identifier
Definition: EnhancerDeclaration.php:24
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\withConfiguration
‪withConfiguration(array $configuration, bool $merge=false)
Definition: EnhancerDeclaration.php:72
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\applyMergedItems
‪applyMergedItems(array $currentItems, array $additionalItems)
Definition: EnhancerDeclaration.php:99
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\hasOnlyNumericKeys
‪hasOnlyNumericKeys(array $items)
Definition: EnhancerDeclaration.php:110
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Applicable
Definition: Applicable.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\withResolveArguments
‪withResolveArguments(array $resolveArguments, bool $merge=false)
Definition: EnhancerDeclaration.php:80
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\__construct
‪__construct(string $identifier)
Definition: EnhancerDeclaration.php:43
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\create
‪static create(string $identifier)
Definition: EnhancerDeclaration.php:38
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\getGenerateParameters
‪array getGenerateParameters()
Definition: EnhancerDeclaration.php:67
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\describe
‪describe()
Definition: EnhancerDeclaration.php:94
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\getConfiguration
‪mixed getConfiguration()
Definition: EnhancerDeclaration.php:51
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\withGenerateParameters
‪withGenerateParameters(array $generateParameters, bool $merge=false)
Definition: EnhancerDeclaration.php:87
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\getResolveArguments
‪array getResolveArguments()
Definition: EnhancerDeclaration.php:59
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration
Definition: EnhancerDeclaration.php:21