Add interface abstractions for SchemaGenerator and Discoverer with DI improvements #215
+135
−25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Introduces interface-based abstractions for schema generation and discovery components, enabling extensibility and proper dependency injection patterns. This allows integration with external schema libraries (e.g., API Platform) and custom discovery implementations.
Motivation and Context
The current implementation tightly couples schema generation to PHP attributes and hardcodes discoverer instantiation within loaders. This makes it difficult to:
This PR decouples these concerns by introducing interfaces and moving object construction responsibilities to the Builder.
Breaking Changes
Minimal breaking changes:
SchemaGenerator::generate()now accepts\Reflectorinstead of\ReflectionMethod|\ReflectionFunctionDiscoveryLoaderconstructor signature changed (internal usage only, constructed by Builder)Users relying on default Builder behavior are not affected.
I suggest that the Discoverer (and probably the DiscoveryLoader) should be marked @internal and some of the classes be marked as
final. I'm unsure if you'd merge this changes as they may break current implementations, let me know.Types of changes
Checklist
Additional context
Changes:
SchemaGeneratorInterfacewithgenerate(\Reflector): arraymethodDiscovererInterface(marked@internal) withdiscover()methodSchemaGeneratornow implementsSchemaGeneratorInterfaceDiscovererandCachedDiscoverernow implementDiscovererInterface(marked@internaland@final)DiscoveryLoadersimplified to pure loader (no longer factory)Builder::setSchemaGenerator()andBuilder::setDiscoverer()for custom implementationsFuture possibilities:
ApiPlatformSchemaProvider)\BadMethodCallException) (note that currently a tool is defined using a method or a function but in the future we). open the possibility that a tool could be referenced as an invoke-able class or any other method).Also relates to #153 (indeed the #153 PR is missing the ArrayLoader change and looking at the code its unclear that the schema generator is used there as well as in the discoverer).