master

laravel/framework

Last updated at: 29/12/2023 09:20

BroadcastServiceProvider.php

TLDR

This file is the BroadcastServiceProvider class in the Illuminate\Broadcasting namespace. It extends the ServiceProvider class and implements the DeferrableProvider interface. It registers the broadcasting service provider, including the BroadcastManager class and the BroadcasterContract interface. It provides these services for the application.

Methods

There are no additional methods defined in this file.

Classes

There are no additional classes defined in this file.

<?php

namespace Illuminate\Broadcasting;

use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract;
use Illuminate\Contracts\Broadcasting\Factory as BroadcastingFactory;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;

class BroadcastServiceProvider extends ServiceProvider implements DeferrableProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(BroadcastManager::class, fn ($app) => new BroadcastManager($app));

        $this->app->singleton(BroadcasterContract::class, function ($app) {
            return $app->make(BroadcastManager::class)->connection();
        });

        $this->app->alias(
            BroadcastManager::class, BroadcastingFactory::class
        );
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [
            BroadcastManager::class,
            BroadcastingFactory::class,
            BroadcasterContract::class,
        ];
    }
}