Skip to content

Commit 2332ad0

Browse files
Merge pull request #578 from appwrite/feat-excludes
2 parents 67c6a72 + 494d977 commit 2332ad0

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

src/SDK/SDK.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,21 @@ public function generate(string $target): void
591591
'methods' => $methods,
592592
];
593593

594+
if ($this->exclude($file, $params)) {
595+
continue;
596+
}
597+
594598
$this->render($template, $destination, $block, $params, $minify);
595599
}
596600
break;
597601
case 'definition':
598602
foreach ($this->spec->getDefinitions() as $key => $definition) {
599603
$params['definition'] = $definition;
600604

605+
if ($this->exclude($file, $params)) {
606+
continue;
607+
}
608+
601609
$this->render($template, $destination, $block, $params, $minify);
602610
}
603611
break;
@@ -617,6 +625,11 @@ public function generate(string $target): void
617625

618626
foreach ($methods as $method) {
619627
$params['method'] = $method;
628+
629+
if ($this->exclude($file, $params)) {
630+
continue;
631+
}
632+
620633
$this->render($template, $destination, $block, $params, $minify);
621634
}
622635
}
@@ -625,6 +638,76 @@ public function generate(string $target): void
625638
}
626639
}
627640

641+
/**
642+
* Determine if a file should be excluded from generation.
643+
*
644+
* Allows for files to be excluded based on:
645+
* - Service name or feature
646+
* - Method name or type
647+
* - Definition name
648+
*
649+
* @param $file
650+
* @param $params
651+
* @return bool
652+
*/
653+
protected function exclude($file, $params): bool
654+
{
655+
$exclude = $file['exclude'] ?? [];
656+
657+
$services = [];
658+
$features = [];
659+
foreach ($exclude['services'] ?? [] as $service) {
660+
if (isset($service['name'])) {
661+
$services[] = $service['name'];
662+
}
663+
if (isset($service['feature'])) {
664+
$features[] = $service['feature'];
665+
}
666+
}
667+
668+
$methods = [];
669+
$types = [];
670+
foreach ($exclude['methods'] ?? [] as $method) {
671+
if (isset($method['name'])) {
672+
$methods[] = $method['name'];
673+
}
674+
if (isset($method['type'])) {
675+
$types[] = $method['type'];
676+
}
677+
}
678+
679+
$definitions = [];
680+
foreach ($exclude['definitions'] ?? [] as $definition) {
681+
if (isset($definition['name'])) {
682+
$definitions[] = $definition['name'];
683+
}
684+
}
685+
686+
if (\in_array($params['service']['name'] ?? '', $services)) {
687+
return true;
688+
}
689+
690+
foreach ($features as $feature) {
691+
if ($params['service']['features'][$feature] ?? false) {
692+
return true;
693+
}
694+
}
695+
696+
if (\in_array($params['method']['name'] ?? '', $methods)) {
697+
return true;
698+
}
699+
700+
if (\in_array($params['method']['type'] ?? '', $types)) {
701+
return true;
702+
}
703+
704+
if (\in_array($params['definition']['name'] ?? '', $definitions)) {
705+
return true;
706+
}
707+
708+
return false;
709+
}
710+
628711
/**
629712
* @param array $methods
630713
* @return bool

0 commit comments

Comments
 (0)