Weave Code
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

Request Collector Bundle Laravel Package

deuzu/request-collector-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require deuzu/request-collector-bundle
    

    Add the bundle to app/AppKernel.php (or config/bundles.php for Symfony Flex):

    new Deuzu\RequestCollectorBundle\DeuzuRequestCollectorBundle(),
    
  2. Configure the Collector Edit app/config/config.yml (or config/packages/deuzu_request_collector.yaml):

    deuzu_request_collector:
        enabled: true
        storage:
            type: file  # or 'database' (requires Doctrine)
            path: "%kernel.logs_dir%/requests"  # For file storage
        email:
            enabled: false  # Set to true to email collected requests
            to: "debug@example.com"
    
  3. First Use Case Access the collector endpoint at /_collector (or your custom route, see below). Send a test request (e.g., via curl or Postman):

    curl -X POST http://your-app/_collector -d '{"test":"data"}' -H "X-Webhook: Test"
    

    Check the configured storage (e.g., var/logs/requests/ for file storage) for the collected request.


Implementation Patterns

Core Workflow

  1. Expose the Collector Endpoint The bundle provides a default route (/collector). Override it in routing.yml:

    deuzu_request_collector_collector:
        path: /webhook-collector
        methods: [POST]
    
  2. Collect Requests Programmatically Trigger collection manually in controllers/services:

    use Deuzu\RequestCollectorBundle\Collector\Collector;
    
    public function someAction(Collector $collector) {
        $request = $this->get('request_stack')->getCurrentRequest();
        $collector->collect($request); // Manually collect a request
    }
    
  3. Extend with Custom Logic Tag a service to run after collection (e.g., for processing):

    services:
        app.request_processor:
            class: AppBundle\Service\RequestProcessor
            tags:
                - { name: deuzu_request_collector.post_collect }
    

    Implement the PostCollectInterface:

    use Deuzu\RequestCollectorBundle\Collector\PostCollectInterface;
    
    class RequestProcessor implements PostCollectInterface {
        public function postCollect($requestData) {
            // Custom logic (e.g., save to DB, trigger events)
        }
    }
    
  4. Database Storage (Optional) Enable Doctrine storage in config:

    deuzu_request_collector:
        storage:
            type: database
            entity: AppBundle\Entity\RequestLog
    

    Create a RequestLog entity (extend Deuzu\RequestCollectorBundle\Entity\RequestLog).


Integration Tips

  • Webhook Testing: Use the collector to test webhooks locally before deploying to production.
  • Environment-Specific Config: Disable the collector in production:
    # config_prod.yml
    deuzu_request_collector:
        enabled: false
    
  • Security: Restrict access to the collector endpoint (e.g., IP whitelisting or basic auth):
    deuzu_request_collector:
        security:
            enabled: true
            ip_whitelist: ["192.168.1.100"]
    

Gotchas and Tips

Pitfalls

  1. Archived Package: The last release is from 2017. Verify compatibility with your Symfony version (tested up to Symfony 3.x). Fork or patch if needed.
  2. Storage Quirks:
    • File Storage: Logs may fill up disk space. Implement rotation (e.g., via monolog handlers).
    • Database Storage: Ensure the RequestLog entity is properly mapped to your Doctrine schema.
  3. Email Notifications: If email.enabled: true, configure a valid SMTP server in framework/mailer to avoid failures.
  4. Route Conflicts: The default /_collector route may conflict with other bundles. Customize the route path in config:
    deuzu_request_collector:
        route:
            path: /debug/collector
    

Debugging

  • Missing Requests: Check if the collector is enabled (enabled: true) and the route is properly configured.
  • Storage Issues: Verify write permissions for path (file storage) or Doctrine connection (database storage).
  • Logs: Enable debug mode to see collector-related logs in var/log/dev.log.

Extension Points

  1. Custom Storage: Implement Deuzu\RequestCollectorBundle\Collector\StorageInterface for alternative storage (e.g., Elasticsearch).
  2. Request Filtering: Override the collector service to filter requests (e.g., by header or payload):
    services:
        deuzu_request_collector.collector:
            class: AppBundle\Collector\CustomCollector
            arguments: ["@deuzu_request_collector.storage"]
    
    class CustomCollector extends \Deuzu\RequestCollectorBundle\Collector\Collector {
        protected function shouldCollect(Request $request) {
            return $request->headers->has('X-Collect-Me');
        }
    }
    
  3. Request Transformation: Modify collected data before storage by implementing PostCollectInterface or overriding the collector’s collect() method.

Performance

  • Large Payloads: File storage may slow down for large requests. Consider streaming or chunking for database storage.
  • Memory Usage: Disable email notifications in production to reduce overhead:
    deuzu_request_collector:
        email:
            enabled: false
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware