Class Event
Class Event
Properties summary
- $_data protected
array
Custom data for the method that receives the event
- $_name protected
string
Name of the event
- $_stopped protected
bool
Flags an event as stopped or not, default is false
- $_subject protected
object|null
The object this event applies to (usually the same object that generates the event)
- $data public
array
(deprecated) Custom data for the method that receives the event
- $name public
string
(deprecated) Name of the event
- $result public
mixed
Property used to retain the result value of the event listeners
- $subject public
object
(deprecated) The object this event applies to
Method Summary
Method Detail
__construct() public
__construct(mixed $name, mixed $subject, mixed $data)
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(mixed $attribute)
Provides read-only access for the name and subject properties.
Parameters
-
string
$attribute Attribute name.
Returns
mixed
__set() public
__set(mixed $attribute, mixed $value)
Provides backward compatibility for write access to data and result properties.
Parameters
-
string
$attribute Attribute name.
-
mixed
$value The value to set.
data() public
data(mixed $key)
Access the event data/payload.
Parameters
-
string|null
$key optional 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() public
getData(mixed $key)
Access the event data/payload.
Parameters
-
string|null
$key optional 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() public
getName()
Returns the name of this event. This is usually used as the event identifier
Returns
string
getResult() public
getResult()
The result value of the event listeners
Returns
mixed
getSubject() public
getSubject()
Returns the subject of this event
Returns
object
isStopped() public
isStopped()
Check if the event is stopped
Returns
bool
True if the event is stopped
name() public
name()
Returns the name of this event. This is usually used as the event identifier
Returns
string
result() public
result()
The result value of the event listeners
Returns
mixed
setData() public
setData(mixed $key, mixed $value)
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 The value to set.
Returns
$this
setResult() public
setResult(mixed $value)
Listeners can attach a result value to the event.
Parameters
-
mixed
$value optional The value to set.
Returns
$this
stopPropagation() public
stopPropagation()
Stops the event from being used anymore
subject() public
subject()
Returns the subject of this event
Returns
object
Property Detail
$_data protected
Custom data for the method that receives the event
Type
array
$_name protected
Name of the event
Type
string
$_stopped protected
Flags an event as stopped or not, default is false
Type
bool
$_subject protected
The object this event applies to (usually the same object that generates the event)
Type
object|null
$data public
(deprecated) Custom data for the method that receives the event
Type
array
$name public
(deprecated) Name of the event
Type
string
$result public
Property used to retain the result value of the event listeners
Note: Public access is deprecated, use setResult() and getResult() instead.
Type
mixed
$subject public
(deprecated) The object this event applies to
Type
object
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.Event.Event.html