Service Locator Enhancement
Add Support for Modular OData Service Endpoints
This PR introduces a powerful mechanism for defining modular, multi-endpoint OData services in Laravel when using flat3/lodata. It enables a clean and scalable way to expose different domains or bounded contexts under separate OData endpoints, each with their own $metadata and query surface.
- Fixes #815
- Fixes #581
- Fixes #742
Key Features
- Multiple service endpoints via configuration (
config/lodata.php) - Each endpoint has:
- Its own URI segment (
/odata/{key}/...) - Its own namespace in
$metadata - A
discover()method for dynamic schema registration - Optional pre-generated metadata via
cachedMetadataXMLPath()
- Its own URI segment (
- Built-in performance optimization:
-
discover()is only invoked on-demand - No overhead for regular Laravel routes
-
Implementation Overview
- Introduced ServiceEndpointInterface
- Added dynamic endpoint registration logic to ServiceProvider
- Endpoint resolution via URI prefix (based on
config('lodata.endpoints')) - Schema discovery per endpoint
- Optional static metadata XML serving (
$endpoint->cachedMetadataXMLPath()) to support arbitrary annotations
Documentation
For a detailed overview of the architecture, configuration, and usage of modular service endpoints, please refer to the comprehensive documentation accompanying this pull request.
Benefits
- Clean separation of API domains (e.g., HR, Finance, Projects)
- Flexible architecture: mix static and dynamic metadata
- Optimized performance (no eager booting of OData models)
- No need for extra route definitions
- Easy to scale and maintain
Notes
This PR does not introduce breaking changes. Existing single-endpoint behavior remains the default. If config('lodata.endpoints') is empty, the global service continues to be served as before.
Let me know if you'd like this split into smaller commits or if you'd prefer to review feature-by-feature. Thanks for the great base package! 🙌
@mgerzabek could you rebase on 5.x, I fixed the issue with the tests. Also, please revert the .gitignore that removes the .idea folder - that folder is supposed to be there (https://www.jetbrains.com/help/phpstorm/creating-and-managing-projects.html)
Thanks!
@27pchrisl, I've rebased on 5.x and removed the .idea from .gitignore. Is there anything else that I could do?
Please let me know.
I've opened https://github.com/doctrine/dbal/pull/7050 which should resolve the issue with the tests. @mgerzabek
@27pchrisl — Sorry for the noise, but I just realized that the PR merged yesterday introduced new incompatibilities with mine. Those should be resolved now. However, for some reason, MongoDB is once again causing CI trouble — likely unrelated to this PR.
As announced, this version no longer uses Composer extra for auto-discovery. Instead, the original ServiceProvider was enhanced to eliminate the static route() and endpoint() methods. This brings more flexibility and aligns better with Laravel conventions.
The documentation has been updated accordingly, including a new example of a multi-endpoint-capable service provider for those who need modular setups.
Let me know if anything else needs adjustment — thanks!
Hi @27pchrisl,
thanks again for your feedback and guidance on the rebase and adjustments.
Just wanted to check what the current plans are regarding this PR:
- Do you see modular OData endpoints being merged into the main branch at some point?
- Or would you recommend keeping it as a separate patch for now?
This feature is quite relevant for several projects, so it would be helpful to know whether and when integration into the mainline might be expected.
Thanks a lot for the update! 🙏