Installable via Composer as bdk/pubsub
{
"require": {
"bdk/pubsub": "^3.2"
}
}
Represents a basic event
Events are passed to event subscribers/listeners
__construct(Subject $subject = null[, array<TKey,TValue> $values = array()])
Construct an event with optional subject and values
__debugInfo(): array{
propagationStopped: bool,
subject: class-string|mixed,
values: array<TKey, TValue>,
}
Magic Method
getSubject(): Subject
Get Event's "subject"
isPropagationStopped(): bool
Has propagation been stopped?
If stopped, no further event subscribers will be called
stopPropagation()
Stops the propagation of the event
No further event subscribers will be called
__serialize(): array<TKey,TValue>
Serialize magic method (since php 7.4)
__unserialize(array<TKey,TValue> $data)
Unserialize
getIterator(): ArrayIterator<TKey,TValue>
IteratorAggregate
interface
Iterate over the object like an array.
getValue(TKey $key): TValue|null
Get value by key.
getValues(): array<TKey,TValue>
Get all stored values
hasValue(TKey $key): bool
Does specified key have a value?
jsonSerialize(): array<TKey,TValue>
Implements JsonSerializable
offsetExists(TKey $key): bool
ArrayAccess
hasValue.
offsetGet(TKey $key): TValue|null
ArrayAccess
getValue.
offsetSet(TKey $offset, TValue $value)
ArrayAccess
setValue
offsetUnset(TKey $key)
ArrayAccess
interface
serialize(): string
Implements Serializable
setValue(TKey $key, TValue $value): $this
Set value
setValues(array<TKey,TValue> $values = array()): $this
Clears existing values and sets new values
unserialize(string $data)
Implements Serializable
Event publish/subscribe event manager
__construct()
Constructor
addSubscriberInterface(bdk\PubSub\SubscriberInterface $interface): array<string,list<SubscriberInfoRaw>>
Subscribe to all of the event subscribers provided by passed object
Calls $interface
's getInterfaceSubscribers
method and subscribes accordingly
getSubscribers(string $eventName = null): array
Gets the subscribers of a specific event or all subscribers sorted by descending priority.
If event name is not specified, subscribers for all events will be returned
hasSubscribers(string $eventName = null): bool
Checks whether an event has any registered subscribers.
publish(string $eventName[, mixed $eventOrSubject = null[, array $values = array()]]): bdk\PubSub\Event
Publish/Trigger/Dispatch event
removeSubscriberInterface(bdk\PubSub\SubscriberInterface $interface): array[]
Unsubscribe from all of the event subscribers provided by passed object
Calls $interface
's getInterfaceSubscribers
method and unsubscribes accordingly
subscribe(string $eventName, callable|ClosureFactory $callable[, int $priority = 0[, bool $onlyOnce = false]])
Subscribe to event
It's possible to lazy load the subscriber object via a "closure factory"
array(Closure, 'methodName')
- closure returns object
array(Closure)
- closure returns object that is callable (ie has __invoke
method)
The closure will be called the first time the event occurs
unsubscribe(string $eventName, callable|ClosureFactory $callable)
Removes an event subscriber from the specified event.
Provide event subscribers
getSubscriptions(): array<string,string|array>
Return event subscribers
The array keys are event names and the value can be:
method: priority defaults to 0, onlyOnce defaults to false
array: (required) method, (optional) int
priority, (optional) bool
onlyOnce
array: any combination of the above
method = string|Callable name of public method or Closure
Value store
Note:
__construct(array<TKey,TValue> $values = array())
Constructor
__debugInfo(): array
Magic Method
__serialize(): array<TKey,TValue>
Serialize magic method (since php 7.4)
__unserialize(array<TKey,TValue> $data)
Unserialize
getIterator(): ArrayIterator<TKey,TValue>
IteratorAggregate
interface
Iterate over the object like an array.
getValue(TKey $key): TValue|null
Get value by key.
getValues(): array<TKey,TValue>
Get all stored values
hasValue(TKey $key): bool
Does specified key have a value?
jsonSerialize(): array<TKey,TValue>
Implements JsonSerializable
offsetExists(TKey $key): bool
ArrayAccess
hasValue.
offsetGet(TKey $key): TValue|null
ArrayAccess
getValue.
offsetSet(TKey $offset, TValue $value)
ArrayAccess
setValue
offsetUnset(TKey $key)
ArrayAccess
interface
serialize(): string
Implements Serializable
setValue(TKey $key, TValue $value): $this
Set value
setValues(array<TKey,TValue> $values = array()): $this
Clears existing values and sets new values
unserialize(string $data)
Implements Serializable
onSet(array<TKey,TValue> $values = array())
Extend me to perform action after setting value/values