class BroadcastManager implements Factory mixin Broadcaster

Traits

Hosts must declare a protected array $poolableDrivers containing their default poolable drivers.

Properties

protected Closure> $releaseCallbacks from  HasPoolProxy
protected array $drivers

The array of resolved broadcast drivers.

protected array $customCreators

The registered custom driver creators.

protected array $poolableDrivers

The array of drivers which will be wrapped as pool proxies.

Methods

mixed
createPoolProxy(string $driver, Closure $createCallback, PoolDefinition $definition, string $proxyClass)

Create a pool proxy for an immutable definition.

poolDefinition(string $resource, array $poolConfig, array $fingerprintSource)

Build a namespaced pool definition for a pooled resource.

poolFactory()

Get the shared object-pool factory.

setReleaseCallback(string $driver, Closure $callback)

Set the release callback for a pooled driver.

Closure|null
getReleaseCallback(string $driver)

Get the release callback for a pooled driver.

addPoolableDriver(string $driver)

Add a driver to the poolable-driver list.

removePoolableDriver(string $driver)

Remove a driver from the poolable-driver list.

array
getPoolableDrivers()

Get the poolable-driver list.

setPoolableDrivers(array $poolableDrivers)

Set the poolable-driver list.

mixed
getAttributeValue(object $target, string $attributeClass, string|null $property = null, mixed $default = null)

Get a configuration value from an attribute, falling back to a property.

mixed
extractAttributeValue(object $instance)

Extract the value from an attribute instance.

object|null
getAttributeInstance(object $target, string $attributeClass, ReflectionClass|null $declaringClass = null)

Get an instance of the given attribute class from the target class or its parents.

bool
propertyOverridesAttribute(object $target, ReflectionClass $reflection, string|null $property, ReflectionClass $attributeDeclaringClass)

Determine if a property declared on a child class overrides an inherited attribute.

Closure|null
bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

string|null
resolveConnectionFromQueueRoute(object $queueable, UnitEnum|string|null $queue = null)

Resolve the default connection name for a given queueable instance.

string|null
resolveQueueFromQueueRoute(object $queueable)

Resolve the default queue name for a given queueable instance.

queueRoutes()

Get the queue routes manager instance.

queueRoutesContainer()

Get the container that owns the queue routes.

__construct(Container $app)

Create a new manager instance.

void
routes(array|null $attributes = null)

Register the routes for handling broadcast channel authentication and sockets.

void
userRoutes(array|null $attributes = null)

Register the routes for handling broadcast user authentication.

void
channelRoutes(array|null $attributes = null)

Register the routes for handling broadcast authentication and sockets.

string|null
socket(Request|null $request = null)

Get the socket ID for the given request.

on(array|Channel|string $channels)

Begin sending an anonymous broadcast to the given channels.

private(string $channel)

Begin sending an anonymous broadcast to the given private channels.

presence(string $channel)

Begin sending an anonymous broadcast to the given presence channels.

event(mixed $event = null)

Begin broadcasting an event.

void
queue(mixed $event)

Queue the given event for broadcast.

bool
mustBeUniqueAndCannotAcquireLock(object $event)

Determine if the broadcastable event must be unique and determine if we can acquire the necessary lock.

connection(UnitEnum|string|null $name = null)

Get a broadcaster instance by name.

driver(UnitEnum|string|null $name = null)

Get a driver instance.

get(string $name)

Attempt to get the connection from the local cache.

resolve(string $name)

Resolve the given broadcaster with a pool proxy if needed.

doResolve(string|null $name, array $config)

Resolve the given broadcaster.

callCustomCreator(array $config)

Call a custom driver creator.

createReverbDriver(array $config)

Create an instance of the driver.

createPusherDriver(array $config)

Create an instance of the driver.

Pusher
pusher(array $config)

Get a Pusher instance for the given configuration.

createAblyDriver(array $config)

Create an instance of the driver.

AblyRest
ably(array $config)

Get an Ably instance for the given configuration.

createRedisDriver(array $config)

Create an instance of the driver.

createLogDriver(array $config)

Create an instance of the driver.

createNullDriver(array $config)

Create an instance of the driver.

array|null
getConfig(string $name)

Get the connection configuration.

string
getDefaultDriver()

Get the default driver name.

void
setDefaultDriver(UnitEnum|string $name)

Set the default broadcast driver name.

void
purge(UnitEnum|string|null $name = null)

Disconnect the given driver and remove it from the local cache.

extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

mixed
rescue(Closure $callback)

Execute the given callback using "rescue" if possible.

getApplication()

Get the application instance used by the manager.

setApplication(Container $app)

Set the application instance used by the manager.

forgetDrivers()

Forget all of the resolved driver instances.

mixed
__call(string $method, array $parameters)

Dynamically call the default driver instance.

Details

in HasPoolProxy at line 27
protected mixed createPoolProxy(string $driver, Closure $createCallback, PoolDefinition $definition, string $proxyClass)

Create a pool proxy for an immutable definition.

Parameters

string $driver
Closure $createCallback
PoolDefinition $definition
string $proxyClass

Return Value

mixed

in HasPoolProxy at line 48
protected PoolDefinition poolDefinition(string $resource, array $poolConfig, array $fingerprintSource)

Build a namespaced pool definition for a pooled resource.

Parameters

string $resource
array $poolConfig
array $fingerprintSource

Return Value

PoolDefinition

at line 485
protected Factory poolFactory()

Get the shared object-pool factory.

Return Value

Factory

in HasPoolProxy at line 74
HasPoolProxy setReleaseCallback(string $driver, Closure $callback)

Set the release callback for a pooled driver.

Boot-only. The callback persists on the manager for the worker lifetime and is captured by every subsequently created proxy for the driver.

Parameters

string $driver
Closure $callback

Return Value

HasPoolProxy

in HasPoolProxy at line 84
Closure|null getReleaseCallback(string $driver)

Get the release callback for a pooled driver.

Parameters

string $driver

Return Value

Closure|null

in HasPoolProxy at line 96
HasPoolProxy addPoolableDriver(string $driver)

Add a driver to the poolable-driver list.

Boot-only. The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

string $driver

Return Value

HasPoolProxy

in HasPoolProxy at line 112
HasPoolProxy removePoolableDriver(string $driver)

Remove a driver from the poolable-driver list.

Boot-only. The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

string $driver

Return Value

HasPoolProxy

in HasPoolProxy at line 129
array getPoolableDrivers()

Get the poolable-driver list.

Return Value

array

in HasPoolProxy at line 141
HasPoolProxy setPoolableDrivers(array $poolableDrivers)

Set the poolable-driver list.

Boot-only. The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

array $poolableDrivers

Return Value

HasPoolProxy

protected mixed getAttributeValue(object $target, string $attributeClass, string|null $property = null, mixed $default = null)

Get a configuration value from an attribute, falling back to a property.

Parameters

object $target
string $attributeClass
string|null $property
mixed $default

Return Value

mixed

protected mixed extractAttributeValue(object $instance)

Extract the value from an attribute instance.

Parameters

object $instance

Return Value

mixed

protected object|null getAttributeInstance(object $target, string $attributeClass, ReflectionClass|null $declaringClass = null)

Get an instance of the given attribute class from the target class or its parents.

Parameters

object $target
string $attributeClass
ReflectionClass|null $declaringClass

Return Value

object|null

protected bool propertyOverridesAttribute(object $target, ReflectionClass $reflection, string|null $property, ReflectionClass $attributeDeclaringClass)

Determine if a property declared on a child class overrides an inherited attribute.

Parameters

object $target
ReflectionClass $reflection
string|null $property
ReflectionClass $attributeDeclaringClass

Return Value

bool

protected Closure|null bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

Parameters

Closure $callback

Return Value

Closure|null

Exceptions

ReflectionException

string|null resolveConnectionFromQueueRoute(object $queueable, UnitEnum|string|null $queue = null)

Resolve the default connection name for a given queueable instance.

Parameters

object $queueable
UnitEnum|string|null $queue

the caller-selected queue, overriding the queueable's queue when resolving a forwarded connection

Return Value

string|null

string|null resolveQueueFromQueueRoute(object $queueable)

Resolve the default queue name for a given queueable instance.

Parameters

object $queueable

Return Value

string|null

protected QueueRoutes queueRoutes()

Get the queue routes manager instance.

Return Value

QueueRoutes

at line 256
protected Container queueRoutesContainer()

Get the container that owns the queue routes.

Return Value

Container

at line 79
__construct(Container $app)

Create a new manager instance.

Parameters

Container $app

at line 87
void routes(array|null $attributes = null)

Register the routes for handling broadcast channel authentication and sockets.

Parameters

array|null $attributes

Return Value

void

at line 110
void userRoutes(array|null $attributes = null)

Register the routes for handling broadcast user authentication.

Parameters

array|null $attributes

Return Value

void

at line 135
void channelRoutes(array|null $attributes = null)

Register the routes for handling broadcast authentication and sockets.

Alias of "routes" method.

Parameters

array|null $attributes

Return Value

void

at line 143
string|null socket(Request|null $request = null)

Get the socket ID for the given request.

Parameters

Request|null $request

Return Value

string|null

at line 158
AnonymousEvent on(array|Channel|string $channels)

Begin sending an anonymous broadcast to the given channels.

Parameters

array|Channel|string $channels

Return Value

AnonymousEvent

at line 166
AnonymousEvent private(string $channel)

Begin sending an anonymous broadcast to the given private channels.

Parameters

string $channel

Return Value

AnonymousEvent

at line 174
AnonymousEvent presence(string $channel)

Begin sending an anonymous broadcast to the given presence channels.

Parameters

string $channel

Return Value

AnonymousEvent

at line 182
PendingBroadcast event(mixed $event = null)

Begin broadcasting an event.

Parameters

mixed $event

Return Value

PendingBroadcast

at line 193
void queue(mixed $event)

Queue the given event for broadcast.

Parameters

mixed $event

Return Value

void

at line 264
protected bool mustBeUniqueAndCannotAcquireLock(object $event)

Determine if the broadcastable event must be unique and determine if we can acquire the necessary lock.

Parameters

object $event

Return Value

bool

at line 273
Broadcaster connection(UnitEnum|string|null $name = null)

Get a broadcaster instance by name.

Parameters

UnitEnum|string|null $name

Return Value

Broadcaster

at line 281
Broadcaster driver(UnitEnum|string|null $name = null)

Get a driver instance.

Parameters

UnitEnum|string|null $name

Return Value

Broadcaster

at line 297
protected Broadcaster get(string $name)

Attempt to get the connection from the local cache.

Parameters

string $name

Return Value

Broadcaster

at line 308
protected Broadcaster resolve(string $name)

Resolve the given broadcaster with a pool proxy if needed.

Parameters

string $name

Return Value

Broadcaster

Exceptions

InvalidArgumentException
RuntimeException

at line 334
protected Broadcaster doResolve(string|null $name, array $config)

Resolve the given broadcaster.

Parameters

string|null $name
array $config

Return Value

Broadcaster

Exceptions

InvalidArgumentException
RuntimeException

at line 364
protected Broadcaster callCustomCreator(array $config)

Call a custom driver creator.

Parameters

array $config

Return Value

Broadcaster

at line 372
protected Broadcaster createReverbDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 380
protected Broadcaster createPusherDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 392
Pusher pusher(array $config)

Get a Pusher instance for the given configuration.

Parameters

array $config

Return Value

Pusher

at line 423
protected Broadcaster createAblyDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 431
AblyRest ably(array $config)

Get an Ably instance for the given configuration.

Parameters

array $config

Return Value

AblyRest

at line 439
protected Broadcaster createRedisDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 457
protected Broadcaster createLogDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 465
protected Broadcaster createNullDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 473
protected array|null getConfig(string $name)

Get the connection configuration.

Parameters

string $name

Return Value

array|null

at line 493
string getDefaultDriver()

Get the default driver name.

Return Value

string

at line 503
void setDefaultDriver(UnitEnum|string $name)

Set the default broadcast driver name.

Boot-only. Mutates process-global config; per-request use races across coroutines.

Parameters

UnitEnum|string $name

Return Value

void

at line 517
void purge(UnitEnum|string|null $name = null)

Disconnect the given driver and remove it from the local cache.

Boot or tests only, plus operational recovery for explicitly pooled drivers. Direct drivers are only removed from the manager cache; an explicitly pooled driver also invalidates its shared pool.

Parameters

UnitEnum|string|null $name

Return Value

void

at line 564
BroadcastManager extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

Anonymous closures run in this manager's class scope; non-static closures also receive the manager as $this.

Boot-only. The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent broadcaster resolution.

Parameters

string $driver
Closure $callback

Return Value

BroadcastManager

at line 581
protected mixed rescue(Closure $callback)

Execute the given callback using "rescue" if possible.

Parameters

Closure $callback

Return Value

mixed

at line 589
Container getApplication()

Get the application instance used by the manager.

Return Value

Container

at line 601
BroadcastManager setApplication(Container $app)

Set the application instance used by the manager.

Tests only. Swaps the singleton's container reference; per-request use races across coroutines and breaks every concurrent request resolving broadcasters through this manager.

Parameters

Container $app

Return Value

BroadcastManager

at line 614
BroadcastManager forgetDrivers()

Forget all of the resolved driver instances.

Boot or tests only. This is cache-only: pooled broadcasters remain shared resources until purged or reclaimed by their idle TTL.

Return Value

BroadcastManager

at line 624
mixed __call(string $method, array $parameters)

Dynamically call the default driver instance.

Parameters

string $method
array $parameters

Return Value

mixed