@@ -103,6 +103,9 @@ public function __construct(Language $language, Spec $spec)
103103 $ this ->twig ->addFilter (new TwigFilter ('caseUcfirst ' , function ($ value ) {
104104 return ucfirst ($ this ->helperCamelCase ($ value ));
105105 }));
106+ $ this ->twig ->addFilter (new TwigFilter ('caseUcwords ' , function ($ value ) {
107+ return ucwords ($ value , " -_ " );
108+ }));
106109 $ this ->twig ->addFilter (new TwigFilter ('caseLcfirst ' , function ($ value ) {
107110 return lcfirst ((string )$ value );
108111 }));
@@ -588,13 +591,21 @@ public function generate(string $target): void
588591 'methods ' => $ methods ,
589592 ];
590593
594+ if ($ this ->exclude ($ file , $ params )) {
595+ continue ;
596+ }
597+
591598 $ this ->render ($ template , $ destination , $ block , $ params , $ minify );
592599 }
593600 break ;
594601 case 'definition ' :
595602 foreach ($ this ->spec ->getDefinitions () as $ key => $ definition ) {
596603 $ params ['definition ' ] = $ definition ;
597604
605+ if ($ this ->exclude ($ file , $ params )) {
606+ continue ;
607+ }
608+
598609 $ this ->render ($ template , $ destination , $ block , $ params , $ minify );
599610 }
600611 break ;
@@ -614,6 +625,11 @@ public function generate(string $target): void
614625
615626 foreach ($ methods as $ method ) {
616627 $ params ['method ' ] = $ method ;
628+
629+ if ($ this ->exclude ($ file , $ params )) {
630+ continue ;
631+ }
632+
617633 $ this ->render ($ template , $ destination , $ block , $ params , $ minify );
618634 }
619635 }
@@ -622,6 +638,76 @@ public function generate(string $target): void
622638 }
623639 }
624640
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+
625711 /**
626712 * @param array $methods
627713 * @return bool
0 commit comments