\Cake\EventEvent

Class Event

Summary

Methods
Properties
Constants
__construct()
__get()
__set()
name()
getName()
subject()
getSubject()
stopPropagation()
isStopped()
result()
getResult()
setResult()
data()
getData()
setData()
$result
No constants found
No protected methods found
$_name
$_subject
$_data
$_stopped
N/A
No private methods found
No private properties found
N/A

Properties

$result

$result : mixed

Property used to retain the result value of the event listeners

Note: Public access is deprecated, use setResult() and getResult() instead.

Type

mixed

$_name

$_name : string

Name of the event

Type

string

$_subject

$_subject : object|null

The object this event applies to (usually the same object that generates the event)

Type

object|null

$_data

$_data : array

Custom data for the method that receives the event

Type

array

$_stopped

$_stopped : boolean

Flags an event as stopped or not, default is false

Type

boolean

Methods

__construct()

__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

the object that this event applies to (usually the object that is generating the event)

array|\ArrayAccess|null $data

any value you wish to be transported with this event to it can be read by listeners

__get()

__get(string  $attribute) : mixed

Provides read-only access for the name and subject properties.

Parameters

string $attribute

Attribute name.

Returns

mixed

__set()

__set(string  $attribute, mixed  $value) : void

Provides backward compatibility for write access to data and result properties.

Parameters

string $attribute

Attribute name.

mixed $value

The value to set.

name()

name() : string

Returns the name of this event. This is usually used as the event identifier

Returns

string

getName()

getName() : string

Returns the name of this event. This is usually used as the event identifier

Returns

string

subject()

subject() : object

Returns the subject of this event

Returns

object

getSubject()

getSubject() : object

Returns the subject of this event

Returns

object

stopPropagation()

stopPropagation() : void

Stops the event from being used anymore

isStopped()

isStopped() : boolean

Check if the event is stopped

Returns

boolean —

True if the event is stopped

result()

result() : mixed

The result value of the event listeners

Returns

mixed

getResult()

getResult() : mixed

The result value of the event listeners

Returns

mixed

setResult()

setResult(mixed  $value = null) : $this

Listeners can attach a result value to the event.

Parameters

mixed $value

The value to set.

Returns

$this

data()

data(string|null  $key = null) : array|mixed|null

Access the event data/payload.

Parameters

string|null $key

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()

getData(string|null  $key = null) : array|mixed|null

Access the event data/payload.

Parameters

string|null $key

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.

setData()

setData(array|string  $key, mixed  $value = null) : $this

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

The value to set.

Returns

$this