Skip to content

Commit ae7c1e8

Browse files
FRW-11564 Fixes and improvements for Composable BO UI. (#300)
FRW-11564 Fixes and improvements for Composable BO UI.
1 parent f35225e commit ae7c1e8

3 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/Spryker/ApiPlatform/DependencyInjection/Compiler/ApiResourceServiceRegistrationPass.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
*/
3333
class ApiResourceServiceRegistrationPass implements CompilerPassInterface
3434
{
35+
/**
36+
* @var array<string>
37+
*/
38+
protected array $registeredServices = [];
39+
3540
/**
3641
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
3742
*/
@@ -53,16 +58,14 @@ public function process(ContainerBuilder $container): void
5358
return;
5459
}
5560

56-
$registeredServices = [];
57-
5861
foreach ($apiTypes as $apiType) {
5962
$schemaFiles = $this->findSchemaFiles($sourceDirectories, $apiType);
6063

6164
foreach ($schemaFiles as $schemaFile) {
6265
$services = $this->extractServicesFromSchema($schemaFile);
6366

6467
foreach ($services as $serviceClass) {
65-
if ($this->shouldRegisterService($container, $serviceClass, $registeredServices)) {
68+
if ($this->shouldRegisterService($container, $serviceClass)) {
6669
$this->registerService($container, $serviceClass);
6770
}
6871
}
@@ -182,15 +185,11 @@ protected function extractServicesFromSchema(SplFileInfo $schemaFile): array
182185
return $services;
183186
}
184187

185-
/**
186-
* @param array<string> $registeredServices
187-
*/
188188
protected function shouldRegisterService(
189189
ContainerBuilder $container,
190190
string $serviceClass,
191-
array $registeredServices,
192191
): bool {
193-
if (in_array($serviceClass, $registeredServices, true)) {
192+
if (in_array($serviceClass, $this->registeredServices, true)) {
194193
return false;
195194
}
196195

@@ -222,5 +221,6 @@ protected function registerService(ContainerBuilder $container, string $serviceC
222221
}
223222

224223
$container->setDefinition($serviceClass, $definition);
224+
$this->registeredServices[] = $serviceClass;
225225
}
226226
}

src/Spryker/ApiPlatform/Generator/ClassGenerator.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,17 +398,26 @@ protected function extractShortClassName(string $fullyQualifiedClassName): strin
398398
*/
399399
protected function generateOperationAttribute(string $type, array $operation): string
400400
{
401-
if (!isset($operation['validationGroups']) || !is_array($operation['validationGroups'])) {
402-
return sprintf('new %s()', $type);
401+
$params = [];
402+
403+
if (!empty($operation['processor'])) {
404+
$processorShortName = $this->extractShortClassName($operation['processor']);
405+
$params[] = sprintf('processor: %s::class', $processorShortName);
406+
}
407+
408+
if (!empty($operation['validationGroups']) && is_array($operation['validationGroups'])) {
409+
$groupsString = "['" . implode("', '", $operation['validationGroups']) . "']";
410+
$params[] = sprintf('validationContext: [\'groups\' => %s]', $groupsString);
403411
}
404412

405-
$validationGroups = $operation['validationGroups'];
406-
$groupsString = "['" . implode("', '", $validationGroups) . "']";
413+
if ($params === []) {
414+
return sprintf('new %s()', $type);
415+
}
407416

408417
return sprintf(
409-
'new %s(validationContext: [\'groups\' => %s])',
418+
'new %s(%s)',
410419
$type,
411-
$groupsString,
420+
implode(', ', $params),
412421
);
413422
}
414423

src/Spryker/ApiPlatform/Schema/Parser/SchemaParser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ protected function normalizeOperations(array $resource, string $filePath): array
130130

131131
$normalizedOperation = ['type' => $operationType];
132132

133+
if (isset($operation['processor'])) {
134+
$normalizedOperation['processor'] = $operation['processor'];
135+
}
136+
133137
if (isset($operation['validationGroups']) && is_array($operation['validationGroups'])) {
134138
$normalizedOperation['validationGroups'] = $operation['validationGroups'];
135139
}

0 commit comments

Comments
 (0)