master

laravel/framework

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

PrivateChannel.php

TLDR

The PrivateChannel.php file in the Illuminate\Broadcasting namespace contains the PrivateChannel class, which extends the Channel class. It is used to create a new private broadcasting channel.

Classes

PrivateChannel

The PrivateChannel class extends the Channel class and is used to create a new private broadcasting channel. It has a constructor that accepts a parameter $name, which can be an instance of Illuminate\Contracts\Broadcasting\HasBroadcastChannel or a string. If the $name is an instance of HasBroadcastChannel, the broadcastChannel() method is called to get the channel name. Otherwise, the $name is used as the channel name directly. The channel name is then prefixed with "private-" and passed to the parent class constructor.

<?php

namespace Illuminate\Broadcasting;

use Illuminate\Contracts\Broadcasting\HasBroadcastChannel;

class PrivateChannel extends Channel
{
    /**
     * Create a new channel instance.
     *
     * @param  \Illuminate\Contracts\Broadcasting\HasBroadcastChannel|string  $name
     * @return void
     */
    public function __construct($name)
    {
        $name = $name instanceof HasBroadcastChannel ? $name->broadcastChannel() : $name;

        parent::__construct('private-'.$name);
    }
}