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

Pusher Bundle Laravel Package

b3da/pusher-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require b3da/pusher-bundle "dev-master"
    

    Add to AppKernel.php:

    new b3da\PusherBundle\b3daPusherBundle(),
    
  2. Configure (config/packages/b3da_pusher.yaml):

    b3da_pusher:
        fcm:
            server_key: "%env(FCM_SERVER_KEY)%"
        apn:
            passphrase: "%env(APN_PASSPHRASE)%"
            cert_path: "%kernel.project_dir%/config/apn_cert.pem"
    
  3. First Use Case: Send an FCM notification:

    use b3da\PusherBundle\Model\Message;
    use b3da\PusherBundle\Service\Android\Fcm;
    
    $fcm = $this->get('b3da_pusher.android.fcm');
    $message = new Message('Hello', 'Your notification body');
    $fcm->notify('device_token_here', $message->composeAndroidFcmMessage());
    $response = $fcm->getOutputAsObject();
    

Implementation Patterns

Core Workflow

  1. Message Composition: Use b3da\PusherBundle\Model\Message to create structured payloads:

    $message = new Message(
        'Title',
        'Body',
        'default', // sound
        1          // notification ID
    );
    
  2. Service Injection: Inject services via Symfony’s DI container:

    $fcm = $this->get('b3da_pusher.android.fcm');
    $apn = $this->get('b3da_pusher.ios.apn');
    
  3. Batch Notifications: Loop through recipients and send:

    foreach ($deviceTokens as $token) {
        $fcm->notify($token, $message->composeAndroidFcmMessage());
    }
    
  4. Error Handling: Check $fcm->getOutputAsObject() for response metadata (e.g., success, failure).


Integration Tips

  • Environment Variables: Store keys in .env (e.g., FCM_SERVER_KEY=your_key_here) and reference via %env().

  • Custom Payloads: Extend Message to add custom data:

    $message->addData(['key' => 'value']);
    
  • APNs Environment: Toggle between sandbox/production by updating server_url in config.

  • Logging: Wrap notify() calls in try-catch to log failures:

    try {
        $fcm->notify($token, $payload);
    } catch (\Exception $e) {
        $this->logger->error('FCM Error: ' . $e->getMessage());
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated GCM: Avoid using gcm—migrate to fcm (Firebase Cloud Messaging) as GCM is obsolete.

  2. APNs Certificate Path: Ensure cert_path is relative to the project root (not public/ or vendor/).

  3. Proxy Configuration: If behind a proxy, set proxy in config (e.g., proxy: 'http://proxy:port').

  4. Message Validation: FCM/APNs may reject malformed payloads. Validate with:

    $fcm->validatePayload($payload); // Hypothetical; check bundle docs.
    
  5. Rate Limits: APNs has strict rate limits (~240 messages/minute). Implement exponential backoff for retries.


Debugging

  • Response Inspection: Dump raw responses to debug:

    dump($fcm->getOutputAsString());
    
  • APNs Errors: APNs returns numeric errors (e.g., 8 = "Missing Device Token"). Map these to user-friendly messages.

  • FCM Logging: Enable FCM debug mode (if supported) via config:

    fcm:
        debug: true
    

Extension Points

  1. Custom Services: Extend b3da\PusherBundle\Service\AbstractPusher to add new providers (e.g., WebPush).

  2. Message Transformers: Override compose*Message() methods in a custom Message class for platform-specific tweaks.

  3. Event Listeners: Dispatch events post-notification (e.g., pusher.notification.sent) using Symfony’s event system.

  4. Queue Integration: Offload notifications to a queue (e.g., Symfony Messenger) for async processing:

    $this->get('messenger')->dispatch(new SendPushNotification($token, $payload));
    
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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator