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
- 
        $_data protectedarrayCustom data for the method that receives the event 
- 
        $_name protectedstringName of the event 
- 
        $_stopped protectedboolFlags an event as stopped or not, default is false 
- 
        $_subject protectedobjectThe object this event applies to (usually the same object that generates the event) 
- 
        $data public @propertyarray(deprecated) Custom data for the method that receives the event 
- 
        $name public @propertystring(deprecated) Name of the event 
- 
        $result public @propertymixed(deprecated) Property used to retain the result value of the event listeners 
- 
        $subject public @propertyobject(deprecated) The object this event applies to 
Method Summary
- 
          __construct() publicConstructor 
- 
          __get() public deprecatedProvides read-only access for the name and subject properties. 
- 
          __set() public deprecatedProvides backward compatibility for write access to data and result properties. 
- 
          data() public deprecatedAccess the event data/payload. 
- 
          getData() publicAccess the event data/payload. 
- 
          getName() publicReturns the name of this event. This is usually used as the event identifier 
- 
          getResult() publicThe result value of the event listeners 
- 
          getSubject() publicReturns the subject of this event 
- 
          isStopped() publicCheck if the event is stopped 
- 
          name() public deprecatedReturns the name of this event. This is usually used as the event identifier 
- 
          result() public deprecatedThe result value of the event listeners 
- 
          setData() publicAssigns a value to the data/payload of this event. 
- 
          setResult() publicListeners can attach a result value to the event. 
- 
          stopPropagation() publicStops the event from being used anymore 
- 
          subject() public deprecatedReturns the subject of this event 
Method Detail
__construct() ¶ public
__construct(string $name, object|null $subject = null, array|ArrayAccess|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|ArrayAccess|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): mixedProvides read-only access for the name and subject properties.
Parameters
- 
                string$attribute
- Attribute name. 
Returns
mixed__set() ¶ public
__set(string $attribute, mixed $value): voidProvides backward compatibility for write access to data and result properties.
Parameters
- 
                string$attribute
- Attribute name. 
- 
                mixed$value
- The value to set. 
Returns
voiddata() ¶ public
data(string|null $key = null): array|mixed|nullAccess the event data/payload.
Parameters
- 
                string|null$key optional
- The data payload element to return, or null to return all data. 
Returns
array|mixed|nullThe data payload if $key is null, or the data value for the given $key. If the $key does not exist a null value is returned.
getData() ¶ public
getData(string|null $key = null): array|mixed|nullAccess the event data/payload.
Parameters
- 
                string|null$key optional
- The data payload element to return, or null to return all data. 
Returns
array|mixed|nullThe data payload if $key is null, or the data value for the given $key. If the $key does not exist a null value is returned.
getName() ¶ public
getName(): stringReturns the name of this event. This is usually used as the event identifier
Returns
stringisStopped() ¶ public
isStopped(): boolCheck if the event is stopped
Returns
boolTrue if the event is stopped
name() ¶ public
name(): stringReturns the name of this event. This is usually used as the event identifier
Returns
stringsetData() ¶ public
setData(array|string $key, mixed $value = null): $thisAssigns a value to the data/payload of this event.
Parameters
- 
                array|string$key
- An array will replace all payload data, and a key will set just that array item. 
- 
                mixed$value optional
- The value to set. 
Returns
$thissetResult() ¶ public
setResult(mixed $value = null): $thisListeners can attach a result value to the event.
Parameters
- 
                mixed$value optional
- The value to set. 
Returns
$thisstopPropagation() ¶ public
stopPropagation(): voidStops the event from being used anymore
Returns
void