CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.5 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.5
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

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.

Namespace: Cake\Event

Property 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

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

  • $data public @property
    array

    (deprecated) Custom data for the method that receives the event

  • $name public @property
    string

    (deprecated) Name of the event

  • $result public @property
    mixed

    (deprecated) Property used to retain the result value of the event listeners

  • $subject public @property
    object

    (deprecated) The object this event applies to

Method Summary

  • __construct() public

    Constructor

  • __get() public deprecated

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

  • __set() public deprecated

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

  • data() public deprecated

    Access the event data/payload.

  • getData() public

    Access the event data/payload.

  • getName() public

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

  • getResult() public

    The result value of the event listeners

  • getSubject() public

    Returns the subject of this event

  • isStopped() public

    Check if the event is stopped

  • name() public deprecated

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

  • result() public deprecated

    The result value of the event listeners

  • setData() public

    Assigns a value to the data/payload of this event.

  • setResult() public

    Listeners can attach a result value to the event.

  • stopPropagation() public

    Stops the event from being used anymore

  • subject() public deprecated

    Returns the subject of this event

Method Detail

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

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(string $attribute): mixed

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

Parameters
string $attribute

Attribute name.

Returns
mixed

__set() ¶ public

__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.

Returns
void

data() ¶ public

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

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

getData() ¶ public

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

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

getName() ¶ public

getName(): string

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

Returns
string

getResult() ¶ public

getResult(): mixed

The result value of the event listeners

Returns
mixed

getSubject() ¶ public

getSubject(): object

Returns the subject of this event

Returns
object

isStopped() ¶ public

isStopped(): bool

Check if the event is stopped

Returns
bool

name() ¶ public

name(): string

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

Returns
string

result() ¶ public

result(): mixed

The result value of the event listeners

Returns
mixed

setData() ¶ public

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 optional

The value to set.

Returns
$this

setResult() ¶ public

setResult(mixed $value = null): $this

Listeners can attach a result value to the event.

Parameters
mixed $value optional

The value to set.

Returns
$this

stopPropagation() ¶ public

stopPropagation(): void

Stops the event from being used anymore

Returns
void

subject() ¶ public

subject(): object

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

$data ¶ public @property

(deprecated) Custom data for the method that receives the event

Type
array

$name ¶ public @property

(deprecated) Name of the event

Type
string

$result ¶ public @property

(deprecated) Property used to retain the result value of the event listeners

Type
mixed

$subject ¶ public @property

(deprecated) The object this event applies to

Type
object
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs