‪TYPO3CMS  ‪main
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  $multipleTypesConfigurationDotPhp = [
130  'type' => 'PageType',
131  'default' => '.php',
132  'index' => 'index',
133  'map' => [
134  '.php' => 0,
135  'menu.json' => 10,
136  '.xml' => 20,
137  ],
138  ];
139 
140  return [
141  ‪PageTypeDeclaration::create('null ".html"')
142  ->withConfiguration($multipleTypesConfiguration)
143  ->withResolveArguments(['pageType' => 0])
144  ->withVariables(‪Variables::create(['pathSuffix' => '.html', 'index' => 'index'])),
145  ‪PageTypeDeclaration::create('0 ".html"')
146  ->withConfiguration($multipleTypesConfiguration)
147  ->withGenerateParameters(['&type=0'])
148  ->withResolveArguments(['pageType' => 0])
149  ->withVariables(‪Variables::create(['pathSuffix' => '.html', 'index' => 'index'])),
150  ‪PageTypeDeclaration::create('10 "/menu.json"')
151  ->withConfiguration($multipleTypesConfiguration)
152  ->withGenerateParameters(['&type=10'])
153  ->withResolveArguments(['pageType' => 10])
154  ->withVariables(‪Variables::create(['pathSuffix' => '/menu.json', 'index' => ''])),
155  ‪PageTypeDeclaration::create('20 ".xml"')
156  ->withConfiguration($multipleTypesConfiguration)
157  ->withGenerateParameters(['&type=20'])
158  ->withResolveArguments(['pageType' => 20])
159  ->withVariables(‪Variables::create(['pathSuffix' => '.xml', 'index' => 'index'])),
161  ->withConfiguration($singleTypeConfiguration)
162  ->withResolveArguments(['pageType' => 0])
163  ->withVariables(‪Variables::create(['pathSuffix' => '/', 'index' => ''])),
165  ->withConfiguration($singleTypeConfiguration)
166  ->withGenerateParameters(['&type=0'])
167  ->withResolveArguments(['pageType' => 0])
168  ->withVariables(‪Variables::create(['pathSuffix' => '/', 'index' => ''])),
169  ‪PageTypeDeclaration::create('null ".php"')
170  ->withConfiguration($multipleTypesConfigurationDotPhp)
171  ->withResolveArguments(['pageType' => 0])
172  ->withVariables(‪Variables::create(['pathSuffix' => '.php', 'index' => 'index'])),
174  ->withConfiguration($multipleTypesConfigurationDotPhp)
175  ->withGenerateParameters(['&type=0'])
176  ->withResolveArguments(['pageType' => 0])
177  ->withVariables(‪Variables::create(['pathSuffix' => '.php', 'index' => 'index'])),
178  ];
179  }
180 
181  public function ‪compileEnhancerConfiguration(‪TestSet $testSet): array
182  {
183  $enhancerConfiguration = [];
185  foreach ($testSet->‪getApplicables(EnhancerDeclaration::class) as $enhancerDeclaration) {
186  $enhancerConfiguration = array_replace_recursive(
187  $enhancerConfiguration,
188  (new ‪VariableCompiler($enhancerDeclaration->getConfiguration(), $testSet->‪getVariables()))
189  ->compile()
190  ->getResults()
191  );
192  }
194  foreach ($testSet->‪getApplicables(AspectDeclaration::class) as $aspectDeclaration) {
195  $enhancerConfiguration['aspects'] = array_replace_recursive(
196  $enhancerConfiguration['aspects'] ?? [],
197  (new ‪VariableCompiler($aspectDeclaration->getConfiguration(), $testSet->‪getVariables()))
198  ->compile()
199  ->getResults()
200  );
201  }
202  return $enhancerConfiguration;
203  }
204 
205  public function ‪compilePageTypeConfiguration(‪TestSet $testSet): array
206  {
207  $pageTypeConfiguration = [];
208  foreach ($testSet->‪getApplicables(PageTypeDeclaration::class) as $pageTypeDeclaration) {
209  $pageTypeConfiguration = array_replace_recursive(
210  $pageTypeConfiguration,
211  (new ‪VariableCompiler($pageTypeDeclaration->getConfiguration(), $testSet->‪getVariables()))
212  ->compile()
213  ->getResults()
214  );
215  }
216  return $pageTypeConfiguration;
217  }
218 
219  public function ‪compileGenerateParameters(‪TestSet $testSet): string
220  {
221  $generateParameters = [];
223  foreach ($testSet->‪getApplicables(HasGenerateParameters::class) as $applicable) {
224  $generateParameters[] = $applicable->getGenerateParameters();
225  }
226  $generateParameters = (new ‪VariableCompiler($generateParameters, $testSet->‪getVariables()))
227  ->compile()
228  ->getResults();
229  return implode('', array_merge([], ...$generateParameters));
230  }
231 
232  public function ‪compileUrl(‪TestSet $testSet): string
233  {
234  return $testSet->‪getUrl()->apply($testSet->‪getVariables());
235  }
236 
237  public function ‪compileResolveArguments(‪TestSet $testSet): array
238  {
239  $resolveArguments = [];
241  foreach ($testSet->‪getApplicables(HasResolveArguments::class) as $applicable) {
242  $resolveArguments = array_replace_recursive(
243  $resolveArguments,
244  (new ‪VariableCompiler($applicable->getResolveArguments(), $testSet->‪getVariables()))
245  ->compile()
246  ->getResults()
247  );
248  }
249  $resolveArguments['staticArguments'] = $resolveArguments['staticArguments'] ?? [];
250  $resolveArguments['dynamicArguments'] = $resolveArguments['dynamicArguments'] ?? [];
251  $resolveArguments['queryArguments'] = $resolveArguments['queryArguments'] ?? [];
252  // generate ("assume") `routeArguments` from expected static and dynamic arguments if not declared
253  $resolveArguments['routeArguments'] = $resolveArguments['routeArguments'] ?? array_replace_recursive(
254  $resolveArguments['staticArguments'],
255  $resolveArguments['dynamicArguments']
256  );
257  if (preg_match('#\?cHash=([a-z0-9]+)#i', $this->‪compileUrl($testSet), $matches)) {
258  $resolveArguments['dynamicArguments']['cHash'] = $matches[1];
259  $resolveArguments['queryArguments']['cHash'] = $matches[1];
260  }
261 
262  return $resolveArguments;
263  }
264 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\create
‪static create(string $key, $value)
Definition: VariableItem.php:31
‪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:205
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getVariables
‪getVariables()
Definition: TestSet.php:74
‪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:232
‪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:37
‪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:27
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getUrl
‪getUrl()
Definition: TestSet.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getApplicables
‪Applicable[] getApplicables(string $type=null)
Definition: TestSet.php:54
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileResolveArguments
‪compileResolveArguments(TestSet $testSet)
Definition: Builder.php:237
‪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
Definition: Applicable.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileGenerateParameters
‪compileGenerateParameters(TestSet $testSet)
Definition: Builder.php:219
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileEnhancerConfiguration
‪compileEnhancerConfiguration(TestSet $testSet)
Definition: Builder.php:181
‪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:28
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variable\create
‪static create(string $variableName, int $cast=self::CAST_NONE)
Definition: Variable.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variable\CAST_STRING
‪const CAST_STRING
Definition: Variable.php:23