On this page
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
-
$_nameprotectedName of the eventstring -
$_stoppedprotectedFlags an event as stopped or not, default is falseboolean -
$_subjectprotectedThe object this event applies to (usually the same object that generates the event)object -
$datapublicCustom data for the method that receives the eventmixed -
$resultpublicProperty used to retain the result value of the event listenersmixed
Method Summary
-
__construct() publicConstructor
-
__get() publicDynamically returns the name and subject if accessed directly
-
data() publicAccess the event data/payload.
-
isStopped() publicCheck if the event is stopped
-
name() publicReturns the name of this event. This is usually used as the event identifier
-
stopPropagation() publicStops the event from being used anymore
-
subject() publicReturns the subject of this event
Method Detail
__construct()source 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
$subjectoptional null - the object that this event applies to (usually the object that is generating the event)
-
array|null
$dataoptional null - any value you wish to be transported with this event to it can be read by listeners
__get()source public
__get( string $attribute )
Dynamically returns the name and subject if accessed directly
Parameters
-
string
$attribute - Attribute name.
Returns
mixedisStopped()source public
isStopped( )
Check if the event is stopped
Returns
booleanTrue if the event is stopped
name()source public
name( )
Returns the name of this event. This is usually used as the event identifier
Returns
stringProperties detail
$_subjectsource
protected object
The object this event applies to (usually the same object that generates the event)
© 2005–2016 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.
http://api.cakephp.org/3.2/class-Cake.Event.Event.html