Class Event
Class Event
- Cake\Event\Event implements Cake\Event\EventInterface
Properties summary
-
$_data
protectedCustom data for the method that receives the eventarray
-
$_name
protectedName of the eventstring
-
$_stopped
protectedFlags an event as stopped or not, default is falseboolean
-
$_subject
protectedThe object this event applies to (usually the same object that generates the event)object|null
-
$result
publicProperty used to retain the result value of the event listenersmixed
Method Summary
- __construct() publicConstructor
- 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.
- 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
- Returns the name of this event. This is usually used as the event identifier
- The 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
- 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 deprecated
__get( string $attribute )
Provides read-only access for the name and subject properties.
Deprecated
3.4.0 Public properties will be removed.Parameters
- string
$attribute
- Attribute name.
Returns
mixed__set()source public deprecated
__set( string $attribute , mixed $value )
Provides backward compatibility for write access to data and result properties.
Deprecated
3.4.0 Public properties will be removed.Parameters
- string
$attribute
- Attribute name.
- mixed
$value
- The value to set.
data()source public deprecated
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|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()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|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.
Implementation of
Cake\Event\EventInterface::getData()
getName()source public
getName( )
Returns the name of this event. This is usually used as the event identifier
Returns
stringImplementation of
Cake\Event\EventInterface::getName()
getResult()source public
getResult( )
The result value of the event listeners
Returns
mixedImplementation of
Cake\Event\EventInterface::getResult()
getSubject()source public
getSubject( )
Returns the subject of this event
Returns
objectImplementation of
Cake\Event\EventInterface::getSubject()
isStopped()source public
isStopped( )
Check if the event is stopped
Returns
booleanTrue if the event is stopped
Implementation of
Cake\Event\EventInterface::isStopped()
name()source public deprecated
name( )
Returns the name of this event. This is usually used as the event identifier
Deprecated
3.4.0 use getName() instead.Returns
stringresult()source public deprecated
result( )
The result value of the event listeners
Deprecated
3.4.0 use getResult() instead.Returns
mixedsetData()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
Implementation of
Cake\Event\EventInterface::setData()
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
Implementation of
Cake\Event\EventInterface::setResult()
stopPropagation()source public
stopPropagation( )
Stops the event from being used anymore
Implementation of
Cake\Event\EventInterface::stopPropagation()
subject()source public deprecated
subject( )
Returns the subject of this event
Deprecated
3.4.0 use getSubject() instead.Returns
objectProperties detail
$_subjectsource
protected object|null
The object this event applies to (usually the same object that generates the event)
$resultsource
public mixed
Property used to retain the result value of the event listeners
Note: Public access is deprecated, use setResult() and getResult() instead.
© 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.6/class-Cake.Event.Event.html