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

Eventbundle Laravel Package

edemy/eventbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer in your Laravel project (assuming compatibility with Laravel's ecosystem):

    composer require masando/edemy-eventbundle
    

    Publish the bundle's configuration (if applicable):

    php artisan vendor:publish --provider="Masando\eDemyEventBundle\eDemyEventBundleServiceProvider"
    
  2. First Use Case Trigger and listen to a basic event:

    // Dispatch an event
    use Masando\eDemyEventBundle\Events\Event;
    
    event(new Event('user.created', ['user_id' => 1]));
    
    // Listen to the event (register in EventServiceProvider)
    protected $listen = [
        Event::class => [
            'App\Listeners\HandleUserCreated',
        ],
    ];
    
  3. Key Files to Review

    • config/edemy_eventbundle.php (if published)
    • app/Providers/EventServiceProvider.php (for listener binding)
    • src/Events/ (custom event classes)

Implementation Patterns

Core Workflows

1. Event Dispatching

  • Basic Dispatch:
    event(new \Masando\eDemyEventBundle\Events\CustomEvent($data));
    
  • Async Dispatch (if supported):
    event(new \Masando\eDemyEventBundle\Events\AsyncEvent($data))->delay(now()->addSeconds(10));
    
  • Contextual Dispatch (e.g., in controllers):
    public function store(Request $request) {
        $user = User::create($request->all());
        event(new \Masando\eDemyEventBundle\Events\UserCreated($user));
    }
    

2. Listener Registration

  • Global Listeners (in EventServiceProvider):
    protected $listen = [
        \Masando\eDemyEventBundle\Events\UserCreated::class => [
            'App\Listeners\SendWelcomeEmail',
            'App\Listeners\LogUserActivity',
        ],
    ];
    
  • Dynamic Listeners (runtime binding):
    event(new \Masando\eDemyEventBundle\Events\OrderPlaced($order))
        ->listen(function ($event) {
            // Inline logic
        });
    

3. Event Payloads

  • Structured Data:
    event(new \Masando\eDemyEventBundle\Events\PaymentProcessed([
        'amount' => 100,
        'currency' => 'USD',
        'status' => 'completed',
    ]));
    
  • Model-Based Events (e.g., Eloquent models):
    class User {
        protected $dispatchesEvents = [
            'created' => UserCreated::class,
            'deleted' => UserDeleted::class,
        ];
    }
    

4. Integration with Laravel Ecosystem

  • Queue Integration (if events are queued):
    // In EventServiceProvider
    $this->app->bind(
        \Masando\eDemyEventBundle\Contracts\EventDispatcher::class,
        \Masando\eDemyEventBundle\QueueEventDispatcher::class
    );
    
  • Service Container Binding:
    $this->app->singleton(\Masando\eDemyEventBundle\Contracts\EventLogger::class, function ($app) {
        return new \App\Services\CustomEventLogger();
    });
    

Advanced Patterns

Event Chaining

event(new \Masando\eDemyEventBundle\Events\OrderReceived($order))
    ->then(function ($event) {
        // Post-processing
    });

Event Filtering

event(new \Masando\eDemyEventBundle\Events\NotificationSent($notification))
    ->filter(function ($event) {
        return $event->notification->isCritical();
    });

Custom Event Classes

Extend the base event class:

namespace App\Events;

use Masando\eDemyEventBundle\Events\Event;

class ProductUpdated extends Event {
    public $product;
    public $changes;

    public function __construct($product, array $changes) {
        parent::__construct('product.updated');
        $this->product = $product;
        $this->changes = $changes;
    }
}

Gotchas and Tips

Common Pitfalls

  1. Event Naming Collisions

    • Ensure event names (e.g., 'user.created') are unique across the application.
    • Fix: Use namespaced event names like 'app.user.created'.
  2. Listener Performance

    • Heavy listeners can block event dispatching.
    • Fix: Offload work to queues or jobs:
      event(new \Masando\eDemyEventBundle\Events\HeavyEvent($data))
          ->listen(function ($event) {
              dispatch(new ProcessHeavyEventJob($event->data));
          });
      
  3. Missing Event Classes

    • If events aren’t firing, verify the class exists and is autoloaded.
    • Fix: Check composer dump-autoload and namespace imports.
  4. Configuration Overrides

    • Bundle config may not be published by default.
    • Fix: Run php artisan vendor:publish --tag=edemy-eventbundle-config.
  5. Async Event Delays

    • If using async dispatch, ensure the queue worker is running:
      php artisan queue:work
      

Debugging Tips

  1. Event Dispatch Logs Enable Laravel’s event logging in config/logging.php:

    'channels' => [
        'events' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel-events.log'),
            'level' => 'debug',
        ],
    ],
    

    Then dispatch events with:

    event(new \Masando\eDemyEventBundle\Events\DebugEvent($data), ['log' => true]);
    
  2. Listener Debugging Add temporary logging in listeners:

    public function handle(Event $event) {
        \Log::debug('Event handled', ['event' => $event->name, 'data' => $event->data]);
        // ...
    }
    
  3. Event Payload Inspection Dump event data in listeners:

    public function handle(Event $event) {
        dd($event->data); // Debug payload
    }
    

Extension Points

  1. Custom Event Dispatcher Bind a custom dispatcher in EventServiceProvider:

    $this->app->singleton(\Masando\eDemyEventBundle\Contracts\EventDispatcher::class, function ($app) {
        return new \App\Services\CustomEventDispatcher();
    });
    
  2. Event Middleware Add middleware to events (if supported):

    event(new \Masando\eDemyEventBundle\Events\ProtectedEvent($data))
        ->middleware(\App\Middleware\Authenticate::class);
    
  3. Event Subscribers Use subscribers for grouped listeners:

    namespace App\Listeners;
    
    use Masando\eDemyEventBundle\Events\Event;
    use Illuminate\Events\Dispatcher;
    
    class UserEventSubscriber {
        public function subscribe(Dispatcher $events) {
            $events->listen('user.*', 'App\Listeners\HandleUserEvents');
        }
    }
    

    Register in EventServiceProvider:

    protected $subscribe = [
        \App\Listeners\UserEventSubscriber::class,
    ];
    
  4. Event Decorators Decorate the event dispatcher for additional logic:

    $this->app->decorate(
        \Masando\eDemyEventBundle\Contracts\EventDispatcher::class,
        \App\Services\EventDecorator::class
    );
    

Configuration Quirks

  1. Queue Connection Configure the default queue connection in config/queue.php:

    'connections' => [
        'edemy' => [
            'driver' => 'database',
            'table' => 'edemy_events',
            'queue' => 'edemy',
        ],
    ],
    

    Then bind it in EventServiceProvider:

    $this->app['queue']->setDefaultConnection('edemy');
    
  2. Event TTL (Time-to-Live) If the bundle supports event expiration, configure in config/edemy_eventbundle.php:

    'ttl' => [
        'default' => 86400, // 24 hours
        'critical' => 3600, // 1 hour
    ],
    
  3. Event Retries For queued events, configure retries in config/queue.php:

    'failed' => [
        'database' => [
            'table' => 'failed_edemy_events',
            'max_tries' =>
    
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