Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doze Bundle Laravel Package

dbstudios/doze-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dbstudios/doze-bundle
    
  2. Register the Bundle Add to app/AppKernel.php:

    new DaybreakStudios\DozeBundle\DaybreakStudiosDozeBundle(),
    
  3. Configure Services Define services.yml (Symfony 2.x) or config/services.yaml (Symfony 3.x+):

    services:
        app.doze.responder:
            class: DaybreakStudios\DozeBundle\ResponderService
            arguments: ['@serializer', '@request_stack']
    
  4. First Use Case Inject ResponderService into a controller and use it to return standardized API responses:

    use DaybreakStudios\DozeBundle\ResponderService;
    
    class ApiController extends AbstractController
    {
        public function index(ResponderService $responder)
        {
            $data = ['message' => 'Hello, API!'];
            return $responder->respond($data);
        }
    }
    

Implementation Patterns

Standardized API Responses

  • Consistent Structure: Use ResponderService to enforce a uniform response format (e.g., data, meta, errors).

    return $responder->respond($data, 200, ['X-RateLimit-Limit' => 100]);
    
  • Error Handling: Leverage built-in error responses:

    return $responder->error('User not found', 404);
    

Serialization Workflows

  • Custom Normalizers: Extend serialization for complex objects (e.g., Doctrine entities):

    app.serializer.normalizer.entity:
        class: App\Serializer\EntityNormalizer
        arguments: ['@doctrine.orm.entity_manager']
    
  • Pagination: Normalize Doctrine collections to paginated responses:

    $query = $entityManager->createQuery('SELECT u FROM App\Entity\User');
    $users = $responder->paginate($query, $request->query->getInt('page', 1));
    

Integration with Symfony Components

  • Request Handling: Access the RequestStack for dynamic responses:

    $request = $responder->getRequest();
    $format = $request->getRequestFormat();
    
  • Event Listeners: Hook into kernel.response to modify responses globally:

    public function onKernelResponse(GetResponseForControllerResultEvent $event)
    {
        $response = $event->getResponse();
        if ($response instanceof JsonResponse) {
            $response->headers->set('Content-Type', 'application/vnd.api+json');
        }
    }
    

Gotchas and Tips

Pitfalls

  • Outdated Dependencies: The package was last updated in 2018. Ensure compatibility with newer Symfony versions (e.g., SerializerComponent changes in Symfony 4+).

    • Fix: Override services in config/packages/doze.yaml to match your Symfony version.
  • Missing Normalizers: If using Doctrine collections, ensure app.serializer.normalizer.collection is defined (see README). Without it, pagination may fail silently.

  • Circular References: The default serializer may struggle with circular references in entities. Configure a custom normalizer:

    app.serializer.normalizer.object:
        class: Symfony\Component\Serializer\Normalizer\ObjectNormalizer
        arguments:
            - '@doctrine.orm.entity_manager'
            - null
            - null
            - ['enable_max_depth' => true]
    

Debugging

  • Response Inspection: Use Symfony’s VarDumper to debug serialized data:

    $data = $responder->serialize($entity);
    dump($data);
    
  • HTTP Headers: Verify headers are set correctly (e.g., Content-Type: application/json). Use:

    $response = $responder->respond($data);
    dump($response->headers->all());
    

Extension Points

  • Custom Responder: Extend ResponderService to add domain-specific logic:

    class ApiResponder extends ResponderService
    {
        public function respondWithPagination(array $data, int $page)
        {
            $data['meta']['pagination'] = ['page' => $page];
            return parent::respond($data);
        }
    }
    
  • Middleware Integration: Use Symfony’s HttpKernel to wrap responses:

    public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();
        if ($response->headers->get('X-API-Version') === null) {
            $response->headers->set('X-API-Version', '1.0');
        }
    }
    
  • Testing: Mock ResponderService in tests to isolate logic:

    $responder = $this->createMock(ResponderService::class);
    $responder->method('respond')->willReturn(new JsonResponse(['data' => []]));
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin