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.
Properties summary
-
array
Custom data for the method that receives the event -
string
Name of the event -
mixed
Property used to retain the result value of the event listeners -
boolean
Flags an event as stopped or not, default is false -
object
The object this event applies to (usually the same object that generates the event)
Magic properties summary
-
array
(deprecated) Custom data for the method that receives the event -
string
(deprecated) Name of the event -
mixed
(deprecated) Property used to retain the result value of the event listeners -
object
(deprecated) The object this event applies to
Method Summary
- Constructor
- Provides read-only access for the name and subject properties.
- Provides backward compatibility for write access to data and result properties.
- Access the event data/payload.
- Access the event data/payload.
- Returns the name of this event. This is usually used as the event identifier
- The result value of the event listeners
- Returns the subject of this event
- Check if the event is stopped
- Returns the name of this event. This is usually used as the event identifier
- The result value of the event listeners
- Assigns a value to the data/payload of this event.
- Listeners can attach a result value to the event.
- Stops the event from being used anymore
- Returns the subject of this event
Method Detail
__construct()source 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 null - the object that this event applies to (usually the object that is generating the event)
- array|ArrayAccess|null
$data
optional null - any value you wish to be transported with this event to it can be read by listeners
__get()source public
__get( string $attribute )
Provides read-only access for the name and subject properties.
Deprecated
Public properties will be removed.
Parameters
- string
$attribute
- Attribute name.
Returns
mixed
__set()source public
__set( string $attribute , mixed $value )
Provides backward compatibility for write access to data and result properties.
Deprecated
Public properties will be removed.
Parameters
- string
$attribute
- Attribute name.
- mixed
$value
- The value to set.
data()source public
data( string|null $key null )
Access the event data/payload.
Deprecated
3.4.0 use getData() instead.
Parameters
- string|null
$key
optional null - The data payload element to return, or null to return all data.
Returns
array|mixed|null
The 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()source public
getData( string|null $key null )
Access the event data/payload.
Parameters
- string|null
$key
optional null - The data payload element to return, or null to return all data.
Returns
array|mixed|null
The 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()source public
getName( )
Returns the name of this event. This is usually used as the event identifier
Returns
string
getResult()source public
getResult( )
The result value of the event listeners
Returns
mixed
getSubject()source public
getSubject( )
Returns the subject of this event
Returns
object
isStopped()source public
isStopped( )
Check if the event is stopped
Returns
boolean
True if the event is stopped
name()source public
name( )
Returns the name of this event. This is usually used as the event identifier
Deprecated
3.4.0 use getName() instead.
Returns
string
result()source public
result( )
The result value of the event listeners
Deprecated
3.4.0 use getResult() instead.
Returns
mixed
setData()source public
setData( array|string $key , mixed $value null )
Assigns 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 null - The value to set.
Returns
$this
setResult()source public
setResult( mixed $value null )
Listeners can attach a result value to the event.
Parameters
- mixed
$value
optional null - The value to set.
Returns
$this
stopPropagation()source public
stopPropagation( )
Stops the event from being used anymore
subject()source public
subject( )
Returns the subject of this event
Deprecated
3.4.0 use getSubject() instead.
Returns
object
Properties detail
protected array
Custom data for the method that receives the event
protected string
Name of the event
protected mixed
Property used to retain the result value of the event listeners
protected boolean
Flags an event as stopped or not, default is false
protected object
The object this event applies to (usually the same object that generates the event)
Magic properties detail