master

laravel/framework

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

Channel.php

TLDR

The Channel.php file defines the Channel class which implements the Stringable interface. It represents a broadcasting channel and provides methods to create and convert a channel instance to a string.

Classes

Channel

The Channel class represents a broadcasting channel. It has the following properties and methods:

Properties

  • $name: The channel's name (string).

Methods

  • __construct($name): Creates a new channel instance. It accepts a parameter $name which can be either an instance of HasBroadcastChannel or a string. If $name is an instance of HasBroadcastChannel, the broadcastChannel() method is called on it to fetch the channel's name. Otherwise, the provided string is used as the channel's name.
  • __toString(): Converts the channel instance to a string. It returns the channel's name.
<?php

namespace Illuminate\Broadcasting;

use Illuminate\Contracts\Broadcasting\HasBroadcastChannel;
use Stringable;

class Channel implements Stringable
{
    /**
     * The channel's name.
     *
     * @var string
     */
    public $name;

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

    /**
     * Convert the channel instance to a string.
     *
     * @return string
     */
    public function __toString()
    {
        return $this->name;
    }
}