dbstudios/doze
Doze is a small PHP response helper built on Symfony Serializer/HttpFoundation. Configure a serializer + responder to produce encoded responses (e.g., JSON) and use its field selector/attributes support to return only requested fields in API payloads.
Illuminate\Http\Response compatibility). Requires manual bridging.Response facade.Illuminate\Http\Resources\ApiResource).ValidateRequests or Transformers.Doze\Responder in a custom trait/class to adapt to Laravel’s Response object.JsonResponse.JsonResource, Fractal, or API Resources)?spatie/fractal (MIT).ApiResource, Transformers).Doze vs. Laravel’s JsonResource for a sample payload.DozeServiceProvider to bind the serializer/responder.// app/Providers/DozeServiceProvider.php
public function register()
{
$this->app->singleton('doze.serializer', function () {
return new Serializer([
new DateTimeNormalizer(),
new ObjectNormalizer(),
], [new JsonEncoder()]);
});
}
Responder in a facade to adapt to Laravel’s Response:
// app/Facades/DozeResponse.php
public static function json($data, $status = 200)
{
$responder = new Responder(app('doze.serializer'));
$content = $responder->createResponse('json', $data);
return response($content->getContent(), $status, $content->getHeaders());
}
return response()->json($data) with DozeResponse::json($data).symfony/* packages (e.g., symfony/http-foundation).Response: Manual adaptation needed (as shown above).User with Post collections).null values, circular references).DozeServiceProvider and facade.Illuminate\Http\Events\RequestHandled).Doze won’t break Laravel core.composer.json.Doze output for debugging:
\Log::debug('Doze Response', [
'content' => $response->getContent(),
'headers' => $response->getHeaders(),
]);
JsonResponse caching).ab or Laravel Debugbar to compare Doze vs. native JsonResponse.ObjectNormalizer::setIgnoredAttributes() to exclude unnecessary fields.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package abandonment | Broken API responses | Fork + maintain internally |
| Symfony Serializer update | Serialization errors | Test against new versions in CI |
| Circular reference in data | Infinite loop | Configure ObjectNormalizer::setCircularReferenceHandler() |
| Custom normalizer bug | Corrupted payloads | Unit test all normalizers |
| Laravel middleware conflict | Response headers ignored | Ensure Doze headers are merged correctly |
Doze vs. Laravel’s JsonResource.spatie/fractal or Laravel’s built-ins.How can I help you explore Laravel packages today?