@@ -579,6 +579,10 @@ public function generate($target)
579579 'methods ' => $ methods ,
580580 ];
581581
582+ if ($ this ->exclude ($ file , $ params )) {
583+ continue ;
584+ }
585+
582586 $ this ->render ($ template , $ destination , $ block , $ params , $ minify );
583587 }
584588 break ;
@@ -587,6 +591,10 @@ public function generate($target)
587591
588592 $ params ['definition ' ] = $ definition ;
589593
594+ if ($ this ->exclude ($ file , $ params )) {
595+ continue ;
596+ }
597+
590598 $ this ->render ($ template , $ destination , $ block , $ params , $ minify );
591599 }
592600 break ;
@@ -606,6 +614,11 @@ public function generate($target)
606614
607615 foreach ($ methods as $ method ) {
608616 $ params ['method ' ] = $ method ;
617+
618+ if ($ this ->exclude ($ file , $ params )) {
619+ continue ;
620+ }
621+
609622 $ this ->render ($ template , $ destination , $ block , $ params , $ minify );
610623 }
611624 }
@@ -614,6 +627,76 @@ public function generate($target)
614627 }
615628 }
616629
630+ /**
631+ * Determine if a file should be excluded from generation.
632+ *
633+ * Allows for files to be excluded based on:
634+ * - Service name or feature
635+ * - Method name or type
636+ * - Definition name
637+ *
638+ * @param $file
639+ * @param $params
640+ * @return bool
641+ */
642+ protected function exclude ($ file , $ params ): bool
643+ {
644+ $ exclude = $ file ['exclude ' ] ?? [];
645+
646+ $ services = [];
647+ $ features = [];
648+ foreach ($ exclude ['services ' ] ?? [] as $ service ) {
649+ if (isset ($ service ['name ' ])) {
650+ $ services [] = $ service ['name ' ];
651+ }
652+ if (isset ($ service ['feature ' ])) {
653+ $ features [] = $ service ['feature ' ];
654+ }
655+ }
656+
657+ $ methods = [];
658+ $ types = [];
659+ foreach ($ exclude ['methods ' ] ?? [] as $ method ) {
660+ if (isset ($ method ['name ' ])) {
661+ $ methods [] = $ method ['name ' ];
662+ }
663+ if (isset ($ method ['type ' ])) {
664+ $ types [] = $ method ['type ' ];
665+ }
666+ }
667+
668+ $ definitions = [];
669+ foreach ($ exclude ['definitions ' ] ?? [] as $ definition ) {
670+ if (isset ($ definition ['name ' ])) {
671+ $ definitions [] = $ definition ['name ' ];
672+ }
673+ }
674+
675+ if (\in_array ($ params ['service ' ]['name ' ] ?? '' , $ services )) {
676+ return true ;
677+ }
678+
679+ foreach ($ features as $ feature ) {
680+ if ($ params ['service ' ]['features ' ][$ feature ] ?? false ) {
681+ return true ;
682+ }
683+ }
684+
685+ if (\in_array ($ params ['method ' ]['name ' ] ?? '' , $ methods )) {
686+ return true ;
687+ }
688+
689+ if (\in_array ($ params ['method ' ]['type ' ] ?? '' , $ types )) {
690+ return true ;
691+ }
692+
693+ if (\in_array ($ params ['definition ' ]['name ' ] ?? '' , $ definitions )) {
694+ return true ;
695+ }
696+
697+ return false ;
698+ }
699+
617700 /**
618701 * @return bool
619702 */
0 commit comments