EventServiceProvider.php
TLDR
The provided file is EventServiceProvider.php
located in the Illuminate\Events
namespace. It extends the ServiceProvider
class and registers an event service provider.
Methods
register
This method is responsible for registering the service provider. It defines a singleton instance of the events
and initializes it with a closure. The closure creates a new Dispatcher
instance and sets the queue resolver and transaction manager resolver for the dispatcher.
END
<?php
namespace Illuminate\Events;
use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
use Illuminate\Support\ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('events', function ($app) {
return (new Dispatcher($app))->setQueueResolver(function () use ($app) {
return $app->make(QueueFactoryContract::class);
})->setTransactionManagerResolver(function () use ($app) {
return $app->bound('db.transactions')
? $app->make('db.transactions')
: null;
});
});
}
}