Class Event
Represents the transport class of events across the system. It receives a name, subject and an optional payload. The name can be any string that uniquely identifies the event across the application, while the subject represents the object that the event applies to.
Property Summary
-
$_name protected
stringName of the event
-
$_stopped protected
boolFlags an event as stopped or not, default is false
-
$_subject protected
objectThe object this event applies to (usually the same object that generates the event)
-
$data public
mixedCustom data for the method that receives the event
-
$result public
mixedProperty used to retain the result value of the event listeners
Method Summary
-
__construct() public
Constructor
-
__get() public
Dynamically returns the name and subject if accessed directly
-
data() public
Access the event data/payload.
-
isStopped() public
Check if the event is stopped
-
name() public
Returns the name of this event. This is usually used as the event identifier
-
stopPropagation() public
Stops the event from being used anymore
-
subject() public
Returns the subject of this event
Method Detail
__construct() ¶ public
__construct(string $name, object|null $subject = null, array|null $data = null)
Constructor
Examples of usage:
$event = new Event('Order.afterBuy', $this, ['buyer' => $userData]);
$event = new Event('User.afterRegister', $UserModel);
Parameters
-
string$name Name of the event
-
object|null$subject optional the object that this event applies to (usually the object that is generating the event)
-
array|null$data optional any value you wish to be transported with this event to it can be read by listeners
__get() ¶ public
__get(string $attribute): mixed
Dynamically returns the name and subject if accessed directly
Parameters
-
string$attribute Attribute name.
Returns
mixedname() ¶ public
name(): string
Returns the name of this event. This is usually used as the event identifier
Returns
stringstopPropagation() ¶ public
stopPropagation(): void
Stops the event from being used anymore
Returns
voidProperty Detail
$_subject ¶ protected
The object this event applies to (usually the same object that generates the event)
Type
object