66
77use Exception ;
88use InvalidArgumentException ;
9+ use Overblog \GraphQLBundle \Config \PermittedInheritTypeProvider ;
910use Overblog \GraphQLBundle \Enum \TypeEnum ;
1011use function array_column ;
1112use function array_filter ;
@@ -29,6 +30,24 @@ final class InheritanceProcessor implements ProcessorInterface
2930 public const HEIRS_KEY = 'heirs ' ;
3031 public const INHERITS_KEY = 'inherits ' ;
3132
33+ /**
34+ * TODO: refactor. This is dirty solution but quick and with minimal impact on existing structure.
35+ *
36+ * @var class-string<PermittedInheritTypeProvider>
37+ */
38+ private static $ permittedInheritTypeProviderClass = PermittedInheritTypeProvider::class;
39+
40+ /**
41+ * @param class-string<PermittedInheritTypeProvider> $fqcn
42+ */
43+ public static function setPermittedInheritTypeProviderClass (string $ fqcn ): void
44+ {
45+ if (!is_subclass_of ($ fqcn , PermittedInheritTypeProvider::class, true )) {
46+ throw new \InvalidArgumentException (sprintf ('Options must be a FQCN implementing %s ' , PermittedInheritTypeProvider::class));
47+ }
48+ self ::$ permittedInheritTypeProviderClass = $ fqcn ;
49+ }
50+
3251 public static function process (array $ configs ): array
3352 {
3453 $ configs = self ::processConfigsHeirs ($ configs );
@@ -80,10 +99,7 @@ private static function processConfigsInherits(array $configs): array
8099 continue ;
81100 }
82101
83- $ allowedTypes = [$ config ['type ' ]];
84- if (TypeEnum::OBJECT === $ config ['type ' ]) {
85- $ allowedTypes [] = TypeEnum::INTERFACE ;
86- }
102+ $ allowedTypes = self ::getAllowedTypes ($ config ['type ' ]);
87103 $ flattenInherits = self ::flattenInherits ($ name , $ configs , $ allowedTypes );
88104 if (empty ($ flattenInherits )) {
89105 continue ;
@@ -198,4 +214,15 @@ private static function mergeConfigs(array ...$configs): array
198214
199215 return $ result ;
200216 }
217+
218+ /**
219+ * @return string[]
220+ */
221+ private static function getAllowedTypes (string $ type ): array
222+ {
223+ /** @var class-string<PermittedInheritTypeProvider> $class */
224+ $ class = self ::$ permittedInheritTypeProviderClass ;
225+
226+ return (new $ class )->getAllowedTypes ($ type );
227+ }
201228}
0 commit comments