OnceProp
class OnceProp implements Onceable, SupportsLiveUpdates
Traits
Properties
| 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 | $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. |
Methods
Mark the property as live, refreshing it whenever one of the given events is received. Merge properties cannot be live.
Get the number of milliseconds to throttle live updates by.
Get the live-update listeners that should refresh the property. A channel passed to [live] applies only to the events it was passed with.
Resolve the name Hypervel broadcasts the given event as.
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.
Get the channels the given event broadcasts on for the default connection.
Add the given events to the listener for the given channel.
Resolve the given channels into the unprefixed names and types the broadcaster sends them on.
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.
Resolve the name of the given channel, without the prefix Hypervel's channel class added to it.
Invoke a value whose public contract guarantees it is callable.
Call the given value if callable and inject its dependencies.
Determine if the given value is callable, but not a string.
Get the number of seconds until the given DateTime.
Get the "available at" UNIX timestamp.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Mark the prop to be resolved only once.
Set a custom key for resolving the once prop.
Mark the property to be forcefully sent to the client.
Get the expiration timestamp in milliseconds for the once prop.
Create a new once property instance.
Resolve the property value.
Details
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.
in
HasLiveUpdates at line 77
bool
isLive()
Determine if the property should receive live updates.
in
HasLiveUpdates at line 85
int|null
liveThrottle()
Get the number of milliseconds to throttle live updates by.
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.
in
HasLiveUpdates at line 128
protected string
resolveEventName(object|string $event)
Resolve the name Hypervel broadcasts the given event as.
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.
in
HasLiveUpdates at line 196
protected array
broadcastChannels(object $event)
Read the channels off an event instance.
in
HasLiveUpdates at line 223
protected array
channelsForDefaultConnection(object $event, array $channels)
Get the channels the given event broadcasts on for the default connection.
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.
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.
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.
in
HasLiveUpdates at line 346
protected string
channelType(Channel $channel)
Resolve the type of the given channel.
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.
in
ResolvesCallables at line 14
protected mixed
invokeCallable(callable $value)
Invoke a value whose public contract guarantees it is callable.
in
ResolvesCallables at line 22
protected mixed
resolveCallable(mixed $value)
Call the given value if callable and inject its dependencies.
in
ResolvesCallables at line 30
protected bool
useAsCallable(mixed $value)
Determine if the given value is callable, but not a string.
in
InteractsWithTime at line 17
protected int
secondsUntil(DateInterval|DateTimeInterface|int $delay)
Get the number of seconds until the given DateTime.
in
InteractsWithTime at line 29
protected int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)
Get the "available at" UNIX timestamp.
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.
in
InteractsWithTime at line 63
protected int
currentTime()
Get the current system time as a UNIX timestamp.
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.
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.
in
ResolvesOnce at line 58
bool
shouldResolveOnce()
Determine if the prop should be resolved only once.
in
ResolvesOnce at line 66
bool
shouldBeRefreshed()
Determine if the prop should be forcefully refreshed.
in
ResolvesOnce at line 74
string|null
getKey()
Get the custom key for resolving the once prop.
in
ResolvesOnce at line 82
ResolvesOnce
as(BackedEnum|UnitEnum|string $key)
Set a custom key for resolving the once prop.
in
ResolvesOnce at line 96
ResolvesOnce
fresh(bool $value = true)
Mark the property to be forcefully sent to the client.
in
ResolvesOnce at line 106
ResolvesOnce
until(DateTimeInterface|DateInterval|int $delay)
Set the expiration for the once prop.
in
ResolvesOnce at line 116
int|null
expiresAt()
Get the expiration timestamp in milliseconds for the once prop.
at line 23
__construct(callable $callback)
Create a new once property instance.
at line 32
mixed
__invoke()
Resolve the property value.