‪TYPO3CMS  ‪main
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 
45  public function ‪getResolveArguments(): array
46  {
48  }
49 
50  public function ‪getGenerateParameters(): array
51  {
53  }
54 
55  public function ‪withConfiguration(array ‪$configuration, bool $merge = false): self
56  {
57  $target = clone $this;
58 
59  $target->configuration = $merge ? $this->‪applyMergedItems($this->configuration, ‪$configuration) : ‪$configuration;
60  return $target;
61  }
62 
63  public function ‪withResolveArguments(array ‪$resolveArguments, bool $merge = false): self
64  {
65  $target = clone $this;
66  $target->resolveArguments = $merge ? $this->‪applyMergedItems($this->resolveArguments, ‪$resolveArguments) : ‪$resolveArguments;
67  return $target;
68  }
69 
70  public function ‪withGenerateParameters(array ‪$generateParameters, bool $merge = false): self
71  {
72  $target = clone $this;
73  $target->generateParameters = $merge ? $this->‪applyMergedItems($this->generateParameters, ‪$generateParameters) : ‪$generateParameters;
74  return $target;
75  }
76 
77  public function ‪describe(): string
78  {
79  return ‪$this->identifier;
80  }
81 
82  private function ‪applyMergedItems(array $currentItems, array $additionalItems): array
83  {
84  if (empty($additionalItems)) {
85  return $currentItems;
86  }
87  if ($this->‪hasOnlyNumericKeys($additionalItems)) {
88  return array_merge($currentItems, $additionalItems);
89  }
90  return array_replace_recursive($currentItems, $additionalItems);
91  }
92 
93  private function ‪hasOnlyNumericKeys(array $items): bool
94  {
95  $numericItems = array_filter($items, 'is_int', ARRAY_FILTER_USE_KEY);
96  return !empty($numericItems);
97  }
98 }
‪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\getGenerateParameters
‪getGenerateParameters()
Definition: EnhancerDeclaration.php:50
‪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:55
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\applyMergedItems
‪applyMergedItems(array $currentItems, array $additionalItems)
Definition: EnhancerDeclaration.php:82
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\hasOnlyNumericKeys
‪hasOnlyNumericKeys(array $items)
Definition: EnhancerDeclaration.php:93
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Applicable
Definition: Applicable.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\getResolveArguments
‪getResolveArguments()
Definition: EnhancerDeclaration.php:45
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\withResolveArguments
‪withResolveArguments(array $resolveArguments, bool $merge=false)
Definition: EnhancerDeclaration.php:63
‪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\describe
‪describe()
Definition: EnhancerDeclaration.php:77
‪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:70
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration
Definition: EnhancerDeclaration.php:21