‪TYPO3CMS  10.4
Builder.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  public static function ‪create(): self
23  {
24  return new static();
25  }
26 
30  public function ‪declareEnhancers(): array
31  {
32  $routePath = ‪VariableValue::create(
33  '/[[routePrefix]]/[[routeParameter]]',
34  ‪Variables::create(['routeParameter' => '{value}'])
35  );
36  $resolveValue = ‪Variable::create('resolveValue', ‪Variable::CAST_STRING);
37 
38  return [
39  'Simple' => ‪EnhancerDeclaration::create('Simple')
40  ->withConfiguration([
41  'type' => 'Simple',
42  'routePath' => $routePath,
43  '_arguments' => [],
44  ])
45  ->withGenerateParameters([
46  ‪VariableValue::create('&value=[[value]]')
47  ->withRequiredDefinedVariableNames('value'),
48  ])
49  ->withResolveArguments([
50  ‪VariableItem::create('inArguments', [
51  'value' => $resolveValue
52  ]),
53  ]),
54  'Plugin' => ‪EnhancerDeclaration::create('Plugin')
55  ->withConfiguration([
56  'type' => 'Plugin',
57  'routePath' => $routePath,
58  'namespace' => 'testing',
59  '_arguments' => [],
60  ])
61  ->withGenerateParameters([
62  ‪VariableValue::create('&testing[value]=[[value]]')
63  ->withRequiredDefinedVariableNames('value'),
64  ])
65  ->withResolveArguments([
66  ‪VariableItem::create('inArguments', [
67  'testing' => [
68  'value' => $resolveValue,
69  ],
70  ]),
71  ]),
72  'Extbase' => ‪EnhancerDeclaration::create('Extbase')
73  ->withConfiguration([
74  'type' => 'Extbase',
75  'routes' => [
76  [
77  'routePath' => $routePath,
78  '_controller' => 'Link::index',
79  '_arguments' => [],
80  ],
81  ],
82  'extension' => 'testing',
83  'plugin' => 'link',
84  ])
85  ->withGenerateParameters([
86  ‪VariableValue::create('&tx_testing_link[value]=[[value]]')
87  ->withRequiredDefinedVariableNames('value'),
88  '&tx_testing_link[controller]=Link&tx_testing_link[action]=index',
89  ])
90  ->withResolveArguments([
91  ‪VariableItem::create('inArguments', [
92  'tx_testing_link' => [
93  'value' => $resolveValue,
94  ],
95  ]),
96  'staticArguments' => [
97  'tx_testing_link' => [
98  'controller' => 'Link',
99  'action' => 'index',
100  ],
101  ],
102  ])
103  ];
104  }
105 
109  public function ‪declarePageTypes(): array
110  {
111  $multipleTypesConfiguration = [
112  'type' => 'PageType',
113  'default' => '.html',
114  'index' => 'index',
115  'map' => [
116  '.html' => 0,
117  'menu.json' => 10,
118  '.xml' => 20
119  ],
120  ];
121  $singleTypeConfiguration = [
122  'type' => 'PageType',
123  'default' => '/',
124  'index' => '/',
125  'map' => [
126  'menu.json' => 10,
127  ],
128  ];
129 
130  return [
131  ‪PageTypeDeclaration::create('null ".html"')
132  ->withConfiguration($multipleTypesConfiguration)
133  ->withResolveArguments(['pageType' => 0])
134  ->withVariables(‪Variables::create(['pathSuffix' => '.html', 'index' => 'index'])),
135  ‪PageTypeDeclaration::create('0 ".html"')
136  ->withConfiguration($multipleTypesConfiguration)
137  ->withGenerateParameters(['&type=0'])
138  ->withResolveArguments(['pageType' => 0])
139  ->withVariables(‪Variables::create(['pathSuffix' => '.html', 'index' => 'index'])),
140  ‪PageTypeDeclaration::create('10 "/menu.json"')
141  ->withConfiguration($multipleTypesConfiguration)
142  ->withGenerateParameters(['&type=10'])
143  ->withResolveArguments(['pageType' => 10])
144  ->withVariables(‪Variables::create(['pathSuffix' => '/menu.json', 'index' => ''])),
145  ‪PageTypeDeclaration::create('20 ".xml"')
146  ->withConfiguration($multipleTypesConfiguration)
147  ->withGenerateParameters(['&type=20'])
148  ->withResolveArguments(['pageType' => 20])
149  ->withVariables(‪Variables::create(['pathSuffix' => '.xml', 'index' => 'index'])),
151  ->withConfiguration($singleTypeConfiguration)
152  ->withResolveArguments(['pageType' => 0])
153  ->withVariables(‪Variables::create(['pathSuffix' => '/', 'index' => ''])),
155  ->withConfiguration($singleTypeConfiguration)
156  ->withGenerateParameters(['&type=0'])
157  ->withResolveArguments(['pageType' => 0])
158  ->withVariables(‪Variables::create(['pathSuffix' => '/', 'index' => ''])),
159  ];
160  }
161 
162  public function ‪compileEnhancerConfiguration(‪TestSet $testSet): array
163  {
164  $enhancerConfiguration = [];
166  foreach ($testSet->‪getApplicables(EnhancerDeclaration::class) as $enhancerDeclaration) {
167  $enhancerConfiguration = array_replace_recursive(
168  $enhancerConfiguration,
169  (new ‪VariableCompiler($enhancerDeclaration->getConfiguration(), $testSet->‪getVariables()))
170  ->compile()
171  ->getResults()
172  );
173  }
175  foreach ($testSet->‪getApplicables(AspectDeclaration::class) as $aspectDeclaration) {
176  $enhancerConfiguration['aspects'] = array_replace_recursive(
177  $enhancerConfiguration['aspects'] ?? [],
178  (new ‪VariableCompiler($aspectDeclaration->getConfiguration(), $testSet->‪getVariables()))
179  ->compile()
180  ->getResults()
181  );
182  }
183  return $enhancerConfiguration;
184  }
185 
186  public function ‪compilePageTypeConfiguration(‪TestSet $testSet): array
187  {
188  $pageTypeConfiguration = [];
189  foreach ($testSet->‪getApplicables(PageTypeDeclaration::class) as $pageTypeDeclaration) {
190  $pageTypeConfiguration = array_replace_recursive(
191  $pageTypeConfiguration,
192  (new ‪VariableCompiler($pageTypeDeclaration->getConfiguration(), $testSet->‪getVariables()))
193  ->compile()
194  ->getResults()
195  );
196  }
197  return $pageTypeConfiguration;
198  }
199 
200  public function ‪compileGenerateParameters(‪TestSet $testSet): string
201  {
202  $generateParameters = [];
204  foreach ($testSet->‪getApplicables(HasGenerateParameters::class) as $applicable) {
205  $generateParameters[] = $applicable->getGenerateParameters();
206  }
207  $generateParameters = (new ‪VariableCompiler($generateParameters, $testSet->‪getVariables()))
208  ->compile()
209  ->getResults();
210  return implode('', array_merge([], ...$generateParameters));
211  }
212 
213  public function ‪compileUrl(‪TestSet $testSet): string
214  {
215  return $testSet->‪getUrl()->‪apply($testSet->‪getVariables());
216  }
217 
218  public function ‪compileResolveArguments(‪TestSet $testSet): array
219  {
220  $resolveArguments = [];
222  foreach ($testSet->‪getApplicables(HasResolveArguments::class) as $applicable) {
223  $resolveArguments = array_replace_recursive(
224  $resolveArguments,
225  (new ‪VariableCompiler($applicable->getResolveArguments(), $testSet->‪getVariables()))
226  ->compile()
227  ->getResults()
228  );
229  }
230  $resolveArguments['staticArguments'] = $resolveArguments['staticArguments'] ?? [];
231  $resolveArguments['dynamicArguments'] = $resolveArguments['dynamicArguments'] ?? [];
232  $resolveArguments['queryArguments'] = $resolveArguments['queryArguments'] ?? [];
233  // generate ("assume") `routeArguments` from expected static and dynamic arguments if not declared
234  $resolveArguments['routeArguments'] = $resolveArguments['routeArguments'] ?? array_replace_recursive(
235  $resolveArguments['staticArguments'],
236  $resolveArguments['dynamicArguments']
237  );
238  if (preg_match('#\?cHash=([a-z0-9]+)#i', $this->‪compileUrl($testSet), $matches)) {
239  $resolveArguments['dynamicArguments']['cHash'] = $matches[1];
240  $resolveArguments['queryArguments']['cHash'] = $matches[1];
241  }
242 
243  return $resolveArguments;
244  }
245 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\create
‪static create(string $key, $value)
Definition: VariableItem.php:35
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\declarePageTypes
‪PageTypeDeclaration[] declarePageTypes()
Definition: Builder.php:109
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compilePageTypeConfiguration
‪compilePageTypeConfiguration(TestSet $testSet)
Definition: Builder.php:186
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet
Definition: TestSet.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileUrl
‪compileUrl(TestSet $testSet)
Definition: Builder.php:213
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder
Definition: Builder.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\create
‪static create()
Definition: Builder.php:22
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue\create
‪static create(string $value, Variables $defaultVariables=null)
Definition: VariableValue.php:39
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables\create
‪static create(array $items=[])
Definition: Variables.php:22
‪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\TestSet\getVariables
‪Variables getVariables()
Definition: TestSet.php:89
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getApplicables
‪Applicable[] getApplicables(string $type=null)
Definition: TestSet.php:66
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileResolveArguments
‪compileResolveArguments(TestSet $testSet)
Definition: Builder.php:218
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableCompiler
Definition: VariableCompiler.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\PageTypeDeclaration
Definition: PageTypeDeclaration.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getUrl
‪VariableValue getUrl()
Definition: TestSet.php:49
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue\apply
‪apply(Variables $variables)
Definition: VariableValue.php:62
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileGenerateParameters
‪compileGenerateParameters(TestSet $testSet)
Definition: Builder.php:200
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileEnhancerConfiguration
‪compileEnhancerConfiguration(TestSet $testSet)
Definition: Builder.php:162
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\declareEnhancers
‪EnhancerDeclaration[] declareEnhancers()
Definition: Builder.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration
Definition: EnhancerDeclaration.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\PageTypeDeclaration\create
‪static create(string $identifier)
Definition: PageTypeDeclaration.php:42
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variable\create
‪static create(string $variableName, int $cast=self::CAST_NONE)
Definition: Variable.php:35
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variable\CAST_STRING
‪const CAST_STRING
Definition: Variable.php:23