Skip to content

Commit 2efff0f

Browse files
committed
fix: implement service filtering based on exclusion rules
1 parent e9a324e commit 2efff0f

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

src/SDK/SDK.php

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,58 @@ public function getParams(): array
537537
return $this->params;
538538
}
539539

540+
/**
541+
* Get services filtered by exclusion rules
542+
*
543+
* @return array
544+
*/
545+
protected function getFilteredServices(): array
546+
{
547+
$allServices = $this->spec->getServices();
548+
$filteredServices = [];
549+
550+
// Extract exclusion rules for services
551+
$excludeServices = [];
552+
$excludeFeatures = [];
553+
foreach ($this->excludeRules['services'] ?? [] as $service) {
554+
if (isset($service['name'])) {
555+
$excludeServices[] = $service['name'];
556+
}
557+
if (isset($service['feature'])) {
558+
$excludeFeatures[] = $service['feature'];
559+
}
560+
}
561+
562+
foreach ($allServices as $serviceName => $service) {
563+
// Check if service is excluded by name
564+
if (in_array($serviceName, $excludeServices)) {
565+
continue;
566+
}
567+
568+
// Check if service is excluded by feature
569+
$methods = $this->spec->getMethods($serviceName);
570+
$serviceFeatures = [
571+
'upload' => $this->hasUploads($methods),
572+
'location' => $this->hasLocation($methods),
573+
'webAuth' => $this->hasWebAuth($methods),
574+
];
575+
576+
$shouldExclude = false;
577+
foreach ($excludeFeatures as $feature) {
578+
if ($serviceFeatures[$feature] ?? false) {
579+
$shouldExclude = true;
580+
break;
581+
}
582+
}
583+
584+
if (!$shouldExclude) {
585+
$filteredServices[$serviceName] = $service;
586+
}
587+
}
588+
589+
return $filteredServices;
590+
}
591+
540592
/**
541593
* @param string $target
542594
* @throws Throwable
@@ -561,7 +613,7 @@ public function generate(string $target): void
561613
'contactName' => $this->spec->getContactName(),
562614
'contactURL' => $this->spec->getContactURL(),
563615
'contactEmail' => $this->spec->getContactEmail(),
564-
'services' => $this->spec->getServices(),
616+
'services' => $this->getFilteredServices(),
565617
'enums' => $this->spec->getEnums(),
566618
'definitions' => $this->spec->getDefinitions(),
567619
'global' => [
@@ -595,7 +647,7 @@ public function generate(string $target): void
595647
copy(realpath(__DIR__ . '/../../templates/' . $file['template']), $destination);
596648
break;
597649
case 'service':
598-
foreach ($this->spec->getServices() as $key => $service) {
650+
foreach ($this->getFilteredServices() as $key => $service) {
599651
$methods = $this->spec->getMethods($key);
600652
$params['service'] = [
601653
'globalParams' => $service['globalParams'] ?? [],
@@ -628,7 +680,7 @@ public function generate(string $target): void
628680
}
629681
break;
630682
case 'method':
631-
foreach ($this->spec->getServices() as $key => $service) {
683+
foreach ($this->getFilteredServices() as $key => $service) {
632684
$methods = $this->spec->getMethods($key);
633685
$params['service'] = [
634686
'name' => $key,

0 commit comments

Comments
 (0)