class DeferProp implements Deferrable, IgnoreFirstLoad, Mergeable, Onceable, Rescuable, SupportsLiveUpdates

Traits

Properties

protected bool $deferred

Indicates if the property should be deferred.

from  DefersProps
protected string|null $deferGroup

The defer group.

from  DefersProps
protected bool $live

Indicates if the property should receive live updates.

from  HasLiveUpdates
protected array<int, array{events: array<int, class-string|object|Channel|string>}> $liveDeclarations

The events and channels each [live] call declared, kept per call so an explicit channel only applies to its own events.

from  HasLiveUpdates
protected int|null $liveThrottle

The number of milliseconds to throttle live updates by.

from  HasLiveUpdates
protected bool $merge

Indicates if the property should be merged.

from  MergesProps
protected bool $deepMerge

Indicates if the property should be deep merged.

from  MergesProps
protected array<int, string> $matchOn

The properties to match on for merging.

from  MergesProps
protected bool $append

Indicates if the property values should be appended or prepended.

from  MergesProps
protected array<int, string> $appendsAtPaths

The paths to append.

from  MergesProps
protected array<int, string> $prependsAtPaths

The paths to prepend.

from  MergesProps
protected bool $once

Indicates if the prop should be resolved only once.

from  ResolvesOnce
protected bool $refresh

Indicates if the prop should be forcefully refreshed.

from  ResolvesOnce
protected int|null $ttl

The expiration time in seconds.

from  ResolvesOnce
protected string|null $key

The custom key for resolving the once prop.

from  ResolvesOnce
protected callable $callback

The callback to resolve the property.

protected bool $rescue

Indicates if exceptions should be rescued during deferred resolution.

Methods

defer(string|null $group = null)

Mark this property as deferred. Deferred properties are excluded from the initial page load and only evaluated when requested by the frontend, improving initial page performance.

bool
shouldDefer()

Determine if this property should be deferred.

string
group()

Get the defer group for this property.

live(array|object|string|null $on = null, array|Channel|string|null $channel = null, int|null $throttle = null)

Mark the property as live, refreshing it whenever one of the given events is received. Merge properties cannot be live.

bool
isLive()

Determine if the property should receive live updates.

int|null
liveThrottle()

Get the number of milliseconds to throttle live updates by.

array
liveListeners()

Get the live-update listeners that should refresh the property. A channel passed to [live] applies only to the events it was passed with.

string
resolveEventName(object|string $event)

Resolve the name Hypervel broadcasts the given event as.

array
channelsFromEvent(object|string $event)

Gather the channels the given event broadcasts on. A class name is built without its payload, which is all an event needs when its channels do not depend on one.

array
broadcastChannels(object $event)

Read the channels off an event instance.

array
channelsForDefaultConnection(object $event, array $channels)

Get the channels the given event broadcasts on for the default connection.

void
addLiveListener(array $listeners, array $channel, array $events)

Add the given events to the listener for the given channel.

array
resolveChannels(array $channels)

Resolve the given channels into the unprefixed names and types the broadcaster sends them on.

array
resolveChannel(Channel|HasBroadcastChannel|string $channel)

Resolve the given channel into its unprefixed name and type. Hypervel's prefixes follow Pusher's convention, so transports get the type separately and apply their own naming.

string
channelType(Channel $channel)

Resolve the type of the given channel.

string
channelName(Channel $channel, string $type)

Resolve the name of the given channel, without the prefix Hypervel's channel class added to it.

merge()

Mark the property for merging. A live property cannot be merged, since refreshing it would append rather than replace its value.

deepMerge()

Mark the property for deep merging.

matchOn(string|array $matchOn)

Set the properties to match on for merging.

bool
shouldMerge()

Determine if the property should be merged.

bool
shouldDeepMerge()

Determine if the property should be deep merged.

array
matchesOn()

Get the properties to match on for merging.

bool
appendsAtRoot()

Determine if the property should be appended at the root level.

bool
prependsAtRoot()

Determine if the property should be prepended at the root level.

bool
mergesAtRoot()

Determine if the property merges at the root level.

append(bool|string|array $path = true, string|null $matchOn = null)

Specify that the value should be appended, optionally providing a key to append and a property to match on.

prepend(bool|string|array $path = true, string|null $matchOn = null)

Specify that the value should be prepended, optionally providing a key to prepend and a property to match on.

array
appendsAtPaths()

Get the paths to append.

array
prependsAtPaths()

Get the paths to prepend.

mixed
invokeCallable(callable $value)

Invoke a value whose public contract guarantees it is callable.

mixed
resolveCallable(mixed $value)

Call the given value if callable and inject its dependencies.

bool
useAsCallable(mixed $value)

Determine if the given value is callable, but not a string.

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

once(bool $value = true, string|null $as = null, DateTimeInterface|DateInterval|int|null $until = null)

Mark the prop to be resolved only once.

bool
shouldResolveOnce()

Determine if the prop should be resolved only once.

bool
shouldBeRefreshed()

Determine if the prop should be forcefully refreshed.

string|null
getKey()

Get the custom key for resolving the once prop.

as(BackedEnum|UnitEnum|string $key)

Set a custom key for resolving the once prop.

fresh(bool $value = true)

Mark the property to be forcefully sent to the client.

until(DateTimeInterface|DateInterval|int $delay)

Set the expiration for the once prop.

int|null
expiresAt()

Get the expiration timestamp in milliseconds for the once prop.

__construct(callable $callback, string|null $group = null, bool $rescue = false)

Create a new deferred property instance. Deferred properties are excluded from the initial page load and only evaluated when requested by the frontend, improving initial page performance.

mixed
__invoke()

Resolve the property value.

bool
shouldRescue()

Determine if deferred resolution errors should be rescued.

Details

in DefersProps at line 24
DefersProps defer(string|null $group = null)

Mark this property as deferred. Deferred properties are excluded from the initial page load and only evaluated when requested by the frontend, improving initial page performance.

Parameters

string|null $group

Return Value

DefersProps

in DefersProps at line 35
bool shouldDefer()

Determine if this property should be deferred.

Return Value

bool

in DefersProps at line 43
string group()

Get the defer group for this property.

Return Value

string

in HasLiveUpdates at line 58
HasLiveUpdates live(array|object|string|null $on = null, array|Channel|string|null $channel = null, int|null $throttle = null)

Mark the property as live, refreshing it whenever one of the given events is received. Merge properties cannot be live.

Parameters

array|object|string|null $on
array|Channel|string|null $channel
int|null $throttle

Return Value

HasLiveUpdates

in HasLiveUpdates at line 77
bool isLive()

Determine if the property should receive live updates.

Return Value

bool

in HasLiveUpdates at line 85
int|null liveThrottle()

Get the number of milliseconds to throttle live updates by.

Return Value

int|null

in HasLiveUpdates at line 96
array liveListeners()

Get the live-update listeners that should refresh the property. A channel passed to [live] applies only to the events it was passed with.

Return Value

array

in HasLiveUpdates at line 128
protected string resolveEventName(object|string $event)

Resolve the name Hypervel broadcasts the given event as.

Parameters

object|string $event

Return Value

string

in HasLiveUpdates at line 168
protected array channelsFromEvent(object|string $event)

Gather the channels the given event broadcasts on. A class name is built without its payload, which is all an event needs when its channels do not depend on one.

Parameters

object|string $event

Return Value

array

in HasLiveUpdates at line 196
protected array broadcastChannels(object $event)

Read the channels off an event instance.

Parameters

object $event

Return Value

array

in HasLiveUpdates at line 223
protected array channelsForDefaultConnection(object $event, array $channels)

Get the channels the given event broadcasts on for the default connection.

Parameters

object $event
array $channels

Return Value

array

in HasLiveUpdates at line 253
protected void addLiveListener(array $listeners, array $channel, array $events)

Add the given events to the listener for the given channel.

Parameters

array $listeners
array $channel
array $events

Return Value

void

in HasLiveUpdates at line 275
protected array resolveChannels(array $channels)

Resolve the given channels into the unprefixed names and types the broadcaster sends them on.

Parameters

array $channels

Return Value

array

in HasLiveUpdates at line 322
protected array resolveChannel(Channel|HasBroadcastChannel|string $channel)

Resolve the given channel into its unprefixed name and type. Hypervel's prefixes follow Pusher's convention, so transports get the type separately and apply their own naming.

Parameters

Channel|HasBroadcastChannel|string $channel

Return Value

array

in HasLiveUpdates at line 346
protected string channelType(Channel $channel)

Resolve the type of the given channel.

Parameters

Channel $channel

Return Value

string

in HasLiveUpdates at line 359
protected string channelName(Channel $channel, string $type)

Resolve the name of the given channel, without the prefix Hypervel's channel class added to it.

Parameters

Channel $channel
string $type

Return Value

string

in MergesProps at line 52
MergesProps merge()

Mark the property for merging. A live property cannot be merged, since refreshing it would append rather than replace its value.

Return Value

MergesProps

in MergesProps at line 66
MergesProps deepMerge()

Mark the property for deep merging.

Return Value

MergesProps

in MergesProps at line 78
MergesProps matchOn(string|array $matchOn)

Set the properties to match on for merging.

Parameters

string|array $matchOn

Return Value

MergesProps

in MergesProps at line 88
bool shouldMerge()

Determine if the property should be merged.

Return Value

bool

in MergesProps at line 96
bool shouldDeepMerge()

Determine if the property should be deep merged.

Return Value

bool

in MergesProps at line 106
array matchesOn()

Get the properties to match on for merging.

Return Value

array

in MergesProps at line 114
bool appendsAtRoot()

Determine if the property should be appended at the root level.

Return Value

bool

in MergesProps at line 122
bool prependsAtRoot()

Determine if the property should be prepended at the root level.

Return Value

bool

in MergesProps at line 130
protected bool mergesAtRoot()

Determine if the property merges at the root level.

Return Value

bool

in MergesProps at line 140
MergesProps append(bool|string|array $path = true, string|null $matchOn = null)

Specify that the value should be appended, optionally providing a key to append and a property to match on.

Parameters

bool|string|array $path
string|null $matchOn

Return Value

MergesProps

in MergesProps at line 162
MergesProps prepend(bool|string|array $path = true, string|null $matchOn = null)

Specify that the value should be prepended, optionally providing a key to prepend and a property to match on.

Parameters

bool|string|array $path
string|null $matchOn

Return Value

MergesProps

in MergesProps at line 184
array appendsAtPaths()

Get the paths to append.

Return Value

array

in MergesProps at line 194
array prependsAtPaths()

Get the paths to prepend.

Return Value

array

in ResolvesCallables at line 14
protected mixed invokeCallable(callable $value)

Invoke a value whose public contract guarantees it is callable.

Parameters

callable $value

Return Value

mixed

in ResolvesCallables at line 22
protected mixed resolveCallable(mixed $value)

Call the given value if callable and inject its dependencies.

Parameters

mixed $value

Return Value

mixed

in ResolvesCallables at line 30
protected bool useAsCallable(mixed $value)

Determine if the given value is callable, but not a string.

Parameters

mixed $value

Return Value

bool

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 47
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 63
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 71
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

in ResolvesOnce at line 40
ResolvesOnce once(bool $value = true, string|null $as = null, DateTimeInterface|DateInterval|int|null $until = null)

Mark the prop to be resolved only once.

Parameters

bool $value
string|null $as
DateTimeInterface|DateInterval|int|null $until

Return Value

ResolvesOnce

in ResolvesOnce at line 58
bool shouldResolveOnce()

Determine if the prop should be resolved only once.

Return Value

bool

in ResolvesOnce at line 66
bool shouldBeRefreshed()

Determine if the prop should be forcefully refreshed.

Return Value

bool

in ResolvesOnce at line 74
string|null getKey()

Get the custom key for resolving the once prop.

Return Value

string|null

in ResolvesOnce at line 82
ResolvesOnce as(BackedEnum|UnitEnum|string $key)

Set a custom key for resolving the once prop.

Parameters

BackedEnum|UnitEnum|string $key

Return Value

ResolvesOnce

in ResolvesOnce at line 96
ResolvesOnce fresh(bool $value = true)

Mark the property to be forcefully sent to the client.

Parameters

bool $value

Return Value

ResolvesOnce

in ResolvesOnce at line 106
ResolvesOnce until(DateTimeInterface|DateInterval|int $delay)

Set the expiration for the once prop.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

ResolvesOnce

in ResolvesOnce at line 116
int|null expiresAt()

Get the expiration timestamp in milliseconds for the once prop.

Return Value

int|null

at line 34
__construct(callable $callback, string|null $group = null, bool $rescue = false)

Create a new deferred property instance. Deferred properties are excluded from the initial page load and only evaluated when requested by the frontend, improving initial page performance.

Parameters

callable $callback
string|null $group
bool $rescue

at line 44
mixed __invoke()

Resolve the property value.

Return Value

mixed

at line 52
bool shouldRescue()

Determine if deferred resolution errors should be rescued.

Return Value

bool