@@ -591,13 +591,21 @@ public function generate(string $target): void
591
591
'methods ' => $ methods ,
592
592
];
593
593
594
+ if ($ this ->exclude ($ file , $ params )) {
595
+ continue ;
596
+ }
597
+
594
598
$ this ->render ($ template , $ destination , $ block , $ params , $ minify );
595
599
}
596
600
break ;
597
601
case 'definition ' :
598
602
foreach ($ this ->spec ->getDefinitions () as $ key => $ definition ) {
599
603
$ params ['definition ' ] = $ definition ;
600
604
605
+ if ($ this ->exclude ($ file , $ params )) {
606
+ continue ;
607
+ }
608
+
601
609
$ this ->render ($ template , $ destination , $ block , $ params , $ minify );
602
610
}
603
611
break ;
@@ -617,6 +625,11 @@ public function generate(string $target): void
617
625
618
626
foreach ($ methods as $ method ) {
619
627
$ params ['method ' ] = $ method ;
628
+
629
+ if ($ this ->exclude ($ file , $ params )) {
630
+ continue ;
631
+ }
632
+
620
633
$ this ->render ($ template , $ destination , $ block , $ params , $ minify );
621
634
}
622
635
}
@@ -625,6 +638,76 @@ public function generate(string $target): void
625
638
}
626
639
}
627
640
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
+
628
711
/**
629
712
* @param array $methods
630
713
* @return bool
0 commit comments