codememory/entity-response-control
Define response prototypes to shape arrays from Doctrine entities using PHP attributes. Build API-friendly payloads with custom formatting, naming strategies, and decorators, including extra per-object data from additional queries.
Pros:
FilesystemAdapter) reduces reflection overhead, critical for performance in high-traffic Laravel APIs.Cons:
Arrayable or JsonSerializable suffice). May not justify adoption for minimal APIs.ApiResource/Fractal for complex responses, but requires custom middleware to integrate with Laravel’s HTTP pipeline.ResponsePrototypeManager as a singleton). Could leverage Laravel’s bindIf for optional integration.FileCache, Redis) via adapter abstraction.booted event to initialize the manager early.#[Property\Getter]) could break if the library evolves. Risk: Low (MIT license, active maintenance).HttpTests) may need extensions.tap methods in prototypes).ApiResource or JsonSerializable offers?Primary Fit:
ApiResource for complex payloads (e.g., nested resources with custom logic).rebing/graphql-laravel).Secondary Fit:
Avoid If:
Pilot Phase:
ApiResource with a prototype. Compare performance and developer experience.PrototypeResponseMiddleware).Incremental Adoption:
Tooling Integration:
| Laravel Component | Compatibility | Workarounds |
|---|---|---|
| Eloquent Models | High (with getter adjustments) | Replace getAttribute() with getX() methods or use traits. |
| API Resources | Medium (can replace or extend) | Use prototypes in toArray() or as a separate layer. |
| Fractal/JSON:API | Low (parallel but not integrated) | Use prototypes for complex transforms; keep Fractal for standard responses. |
| Laravel Mix/Vite | N/A | No impact. |
| Queue Jobs | High | Format job payloads with prototypes before dispatching. |
| GraphQL | Medium | Use prototypes in resolver logic (custom integration needed). |
| Sanctum/Passport | High | Shape auth payloads (e.g., user profiles) with prototypes. |
| Nova/Filament | High | Override resource responses with prototypes. |
| Horizon/Queues | High | Format job results or failed job payloads. |
Prerequisites:
allow-plugins if using Laravel’s package tools.Core Integration:
ResponsePrototypeManager in AppServiceProvider with caching.Route::get(..., ['prototype' => UserPrototype::class])).Advanced Features:
Optimization:
RedisAdapter.UserPublicPrototype, UserAdminPrototype).How can I help you explore Laravel packages today?