‪TYPO3CMS  11.5
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 {
22  private string ‪$identifier;
23  private array ‪$configuration = [];
24  private array ‪$resolveArguments = [];
25  private array ‪$generateParameters = [];
26 
27  public static function ‪create(string ‪$identifier): self
28  {
29  return new static(‪$identifier);
30  }
31 
32  private function ‪__construct(string ‪$identifier)
33  {
34  $this->identifier = ‪$identifier;
35  }
36 
40  public function ‪getConfiguration()
41  {
43  }
44 
48  public function ‪getResolveArguments(): array
49  {
51  }
52 
56  public function ‪getGenerateParameters(): array
57  {
59  }
60 
61  public function ‪withConfiguration(array ‪$configuration, bool $merge = false): self
62  {
63  $target = clone $this;
64 
65  $target->configuration = $merge ? $this->‪applyMergedItems($this->configuration, ‪$configuration) : ‪$configuration;
66  return $target;
67  }
68 
69  public function ‪withResolveArguments(array ‪$resolveArguments, bool $merge = false): self
70  {
71  $target = clone $this;
72  $target->resolveArguments = $merge ? $this->‪applyMergedItems($this->resolveArguments, ‪$resolveArguments) : ‪$resolveArguments;
73  return $target;
74  }
75 
76  public function ‪withGenerateParameters(array ‪$generateParameters, bool $merge = false): self
77  {
78  $target = clone $this;
79  $target->generateParameters = $merge ? $this->‪applyMergedItems($this->generateParameters, ‪$generateParameters) : ‪$generateParameters;
80  return $target;
81  }
82 
83  public function ‪describe(): string
84  {
85  return ‪$this->identifier;
86  }
87 
88  private function ‪applyMergedItems(array $currentItems, array $additionalItems): array
89  {
90  if (empty($additionalItems)) {
91  return $currentItems;
92  }
93  if ($this->‪hasOnlyNumericKeys($additionalItems)) {
94  return array_merge($currentItems, $additionalItems);
95  }
96  return array_replace_recursive($currentItems, $additionalItems);
97  }
98 
99  private function ‪hasOnlyNumericKeys(array $items): bool
100  {
101  $numericItems = array_filter($items, 'is_int', ARRAY_FILTER_USE_KEY);
102  return !empty($numericItems);
103  }
104 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\$generateParameters
‪array $generateParameters
Definition: EnhancerDeclaration.php:25
‪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:23
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\$resolveArguments
‪array $resolveArguments
Definition: EnhancerDeclaration.php:24
‪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:22
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\withConfiguration
‪withConfiguration(array $configuration, bool $merge=false)
Definition: EnhancerDeclaration.php:61
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\applyMergedItems
‪applyMergedItems(array $currentItems, array $additionalItems)
Definition: EnhancerDeclaration.php:88
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\hasOnlyNumericKeys
‪hasOnlyNumericKeys(array $items)
Definition: EnhancerDeclaration.php:99
‪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:69
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\__construct
‪__construct(string $identifier)
Definition: EnhancerDeclaration.php:32
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\create
‪static create(string $identifier)
Definition: EnhancerDeclaration.php:27
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\getGenerateParameters
‪array getGenerateParameters()
Definition: EnhancerDeclaration.php:56
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\describe
‪describe()
Definition: EnhancerDeclaration.php:83
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\getConfiguration
‪mixed getConfiguration()
Definition: EnhancerDeclaration.php:40
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\withGenerateParameters
‪withGenerateParameters(array $generateParameters, bool $merge=false)
Definition: EnhancerDeclaration.php:76
‪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:48
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration
Definition: EnhancerDeclaration.php:21