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

createMercureDriver(array $config)

Create an instance of the driver.

HubInterface
mercure(array $config)

Get a Mercure hub instance for the given configuration.

bool
broadcastsToSynchronousMercureConnections(mixed $event)

Determine if the given event only targets Mercure connections publishing synchronously.

mercurePoolDefinition(array $config)

Identify the shared HTTP-client pool for construction and invalidation.

int
mercureSubscribeExpiration(array $config)

Get the subscriber token (and cookie) lifetime in whole seconds.

TokenFactoryInterface|null
mercureSubscribeFactory(array $config)

Get the subscriber token factory for the given Mercure configuration.

TokenFactoryInterface
mercureTokenFactory(TokenFactoryInterface $factory, array $claims, array $config)

Add configured claims and resolve the default audience when a token is minted.

mercureChannelEncrypter(array $config)

Get the end-to-end channel encrypter for the given Mercure configuration.

array
mercurePublishClaims(array $config)

Get the additional JWT claims for the publisher side of the given Mercure configuration.

string
mercureSecret(array $config, string $side)

Get the JWT secret for the given side ("subscribe" or "publish") of the given Mercure configuration.

array
mercureClaims(array $config)

Get the additional JWT claims for the given Mercure configuration.

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.

void
dispatchSynchronousBroadcast(BroadcastEvent $event)

Publish synchronously while honoring commit timing and dispatch locks.

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

protected Broadcaster createMercureDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

HubInterface mercure(array $config)

Get a Mercure hub instance for the given configuration.

Parameters

array $config

Return Value

HubInterface

protected bool broadcastsToSynchronousMercureConnections(mixed $event)

Determine if the given event only targets Mercure connections publishing synchronously.

Parameters

mixed $event

Return Value

bool

protected PoolDefinition mercurePoolDefinition(array $config)

Identify the shared HTTP-client pool for construction and invalidation.

Parameters

array $config

Return Value

PoolDefinition

protected int mercureSubscribeExpiration(array $config)

Get the subscriber token (and cookie) lifetime in whole seconds.

Parameters

array $config

Return Value

int

protected TokenFactoryInterface|null mercureSubscribeFactory(array $config)

Get the subscriber token factory for the given Mercure configuration.

Parameters

array $config

Return Value

TokenFactoryInterface|null

protected TokenFactoryInterface mercureTokenFactory(TokenFactoryInterface $factory, array $claims, array $config)

Add configured claims and resolve the default audience when a token is minted.

Parameters

TokenFactoryInterface $factory
array $claims
array $config

Return Value

TokenFactoryInterface

protected ChannelEncrypter|null mercureChannelEncrypter(array $config)

Get the end-to-end channel encrypter for the given Mercure configuration.

Parameters

array $config

Return Value

ChannelEncrypter|null

protected array mercurePublishClaims(array $config)

Get the additional JWT claims for the publisher side of the given Mercure configuration.

Parameters

array $config

Return Value

array

protected string mercureSecret(array $config, string $side)

Get the JWT secret for the given side ("subscribe" or "publish") of the given Mercure configuration.

Parameters

array $config
string $side

Return Value

string

protected array mercureClaims(array $config)

Get the additional JWT claims for the given Mercure configuration.

Parameters

array $config

Return Value

array

in HasPoolProxy at line 28
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 49
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 566
protected Factory poolFactory()

Get the shared object-pool factory.

Return Value

Factory

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

Set the release callback for a pooled driver.

The callback persists on the shared 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 86
Closure|null getReleaseCallback(string $driver)

Get the release callback for a pooled driver.

Parameters

string $driver

Return Value

Closure|null

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

Add a driver to the poolable-driver list.

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 115
HasPoolProxy removePoolableDriver(string $driver)

Remove a driver from the poolable-driver list.

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 133
array getPoolableDrivers()

Get the poolable-driver list.

Return Value

array

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

Set the poolable-driver list.

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 326
protected Container queueRoutesContainer()

Get the container that owns the queue routes.

Return Value

Container

at line 93
__construct(Container $app)

Create a new manager instance.

Parameters

Container $app

at line 101
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 124
void userRoutes(array|null $attributes = null)

Register the routes for handling broadcast user authentication.

Parameters

array|null $attributes

Return Value

void

at line 149
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 157
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 172
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 180
AnonymousEvent private(string $channel)

Begin sending an anonymous broadcast to the given private channels.

Parameters

string $channel

Return Value

AnonymousEvent

at line 188
AnonymousEvent presence(string $channel)

Begin sending an anonymous broadcast to the given presence channels.

Parameters

string $channel

Return Value

AnonymousEvent

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

Begin broadcasting an event.

Parameters

mixed $event

Return Value

PendingBroadcast

at line 207
void queue(mixed $event)

Queue the given event for broadcast.

Parameters

mixed $event

Return Value

void

at line 284
protected void dispatchSynchronousBroadcast(BroadcastEvent $event)

Publish synchronously while honoring commit timing and dispatch locks.

Parameters

BroadcastEvent $event

Return Value

void

at line 334
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 343
Broadcaster connection(UnitEnum|string|null $name = null)

Get a broadcaster instance by name.

Parameters

UnitEnum|string|null $name

Return Value

Broadcaster

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

Get a driver instance.

Parameters

UnitEnum|string|null $name

Return Value

Broadcaster

at line 367
protected Broadcaster get(string $name)

Attempt to get the connection from the local cache.

Parameters

string $name

Return Value

Broadcaster

at line 378
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 404
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 434
protected Broadcaster callCustomCreator(array $config)

Call a custom driver creator.

Parameters

array $config

Return Value

Broadcaster

at line 442
protected Broadcaster createReverbDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 450
protected Broadcaster createPusherDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 462
Pusher pusher(array $config)

Get a Pusher instance for the given configuration.

Parameters

array $config

Return Value

Pusher

at line 504
protected Broadcaster createAblyDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 512
AblyRest ably(array $config)

Get an Ably instance for the given configuration.

Parameters

array $config

Return Value

AblyRest

at line 520
protected Broadcaster createRedisDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 538
protected Broadcaster createLogDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

at line 546
protected Broadcaster createNullDriver(array $config)

Create an instance of the driver.

Parameters

array $config

Return Value

Broadcaster

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

Get the connection configuration.

Parameters

string $name

Return Value

array|null

at line 574
string getDefaultDriver()

Get the default driver name.

Return Value

string

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

Set the default broadcast driver name.

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

Parameters

UnitEnum|string $name

Return Value

void

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

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

Use this to recover broken pooled resources. Mercure and explicitly pooled drivers also close their shared pools. Other connections sharing a pool acquire a fresh one on their next operation.

Parameters

UnitEnum|string|null $name

Return Value

void

at line 652
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.

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 670
protected mixed rescue(Closure $callback)

Execute the given callback using "rescue" if possible.

Parameters

Closure $callback

Return Value

mixed

at line 678
Container getApplication()

Get the application instance used by the manager.

Return Value

Container

at line 692
BroadcastManager setApplication(Container $app)

Set the application instance used by the manager.

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 708
BroadcastManager forgetDrivers()

Forget all of the resolved driver instances.

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

Return Value

BroadcastManager

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

Dynamically call the default driver instance.

Parameters

string $method
array $parameters

Return Value

mixed