CakePHP
  • 文档
    • 手册
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识 & 商标
  • 商业解决方案
  • 周边商品
  • 自驾游
  • 团队
  • 社区
    • 社区
    • 参与进来
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 通讯
    • 领英
    • YouTube
    • 脸书
    • 推特
    • Mastodon
    • 帮助 & 支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 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

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
      • Decorator
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 EventManager

事件管理器负责跟踪事件监听器,将正确的数据传递给它们,并在关联事件触发时按正确顺序触发它们。您可以创建此对象的多个实例来管理本地事件,或保留单个实例并将其传递以管理应用程序中的所有事件。

命名空间: Cake\Event

属性摘要

  • $_eventList protected
    Cake\Event\EventList|null

    事件列表对象。

  • $_generalManager protected static
    Cake\Event\EventManager|null

    全局可用的实例,用于分派从任何范围附加的事件

  • $_isGlobal protected
    bool

    内部标志,用于区分通用管理器和单例

  • $_listeners protected
    array

    与之关联的监听器回调列表

  • $_trackEvents protected
    bool

    如果存在事件列表对象,则启用将事件自动添加到事件列表对象中。

  • $defaultPriority public static
    int

    新附加的监听器的默认优先级队列值

方法摘要

  • __debugInfo() public

    调试友好的对象属性。

  • _attachSubscriber() protected

    辅助函数,将 Cake\Event\EventListenerInterface 类实例的所有实现回调附加为此管理器上的各个方法

  • _callListener() protected

    调用监听器。

  • _detachSubscriber() protected

    辅助函数,用于帮助分离由实现 EventListenerInterface 的对象提供的全部监听器

  • addEventToList() public

    如果事件列表对象存在,则将事件添加到列表中。

  • dispatch() public

    将新事件分派给所有配置的监听器

  • getEventList() public

    返回事件列表。

  • instance() public static

    返回 Cake\Event\EventManager 的全局可用实例,这用于分派从其他管理器创建范围之外附加的事件。通常用于创建钩子系统或类间通信

  • isTrackingEvents() public

    返回此管理器是否设置为跟踪事件

  • listeners() public

    返回特定事件的全部监听器,按调用顺序排列

  • matchingListeners() public

    返回与指定模式匹配的监听器

  • normalizeHandler() protected

    构建单个标准化处理程序。

  • normalizeHandlers() protected

    构建标准化处理程序数组。

  • off() public

    从活动监听器中删除监听器。

  • on() public

    将新监听器添加到事件。

  • prioritisedListeners() public

    返回指定事件键的监听器,按优先级索引

  • setEventList() public

    启用分派事件的列表。

  • trackEvents() public

    在运行时启用/禁用事件跟踪。

  • unsetEventList() public

    禁用分派事件的列表。

方法详细信息

__debugInfo() ¶ public

__debugInfo(): array<string, mixed>

调试友好的对象属性。

返回
array<string, mixed>

_attachSubscriber() ¶ protected

_attachSubscriber(Cake\Event\EventListenerInterface $subscriber): void

辅助函数,将 Cake\Event\EventListenerInterface 类实例的所有实现回调附加为此管理器上的各个方法

参数
Cake\Event\EventListenerInterface $subscriber

事件监听器。

返回
void

_callListener() ¶ protected

_callListener(callable $listener, Cake\Event\EventInterface<TSubject> $event): mixed

调用监听器。

参数
callable $listener

要触发的监听器。

Cake\Event\EventInterface<TSubject> $event

事件实例。

返回
mixed

_detachSubscriber() ¶ protected

_detachSubscriber(Cake\Event\EventListenerInterface $subscriber, string|null $eventKey = null): void

辅助函数,用于帮助分离由实现 EventListenerInterface 的对象提供的全部监听器

参数
Cake\Event\EventListenerInterface $subscriber

要分离的订阅者

string|null $eventKey optional

可选的事件键名称,用于取消订阅监听器

返回
void

addEventToList() ¶ public

addEventToList(Cake\Event\EventInterface<TSubject> $event): $this

如果事件列表对象存在,则将事件添加到列表中。

参数
Cake\Event\EventInterface<TSubject> $event

要添加到列表中的事件。

返回
$this

dispatch() ¶ public

dispatch(Cake\Event\EventInterface<TSubject>|string $event): Cake\Event\EventInterface<TSubject>

将新事件分派给所有配置的监听器

参数
Cake\Event\EventInterface<TSubject>|string $event
返回
Cake\Event\EventInterface<TSubject>

getEventList() ¶ public

getEventList(): Cake\Event\EventList|null

返回事件列表。

返回
Cake\Event\EventList|null

instance() ¶ public static

instance(Cake\Event\EventManager|null $manager = null): Cake\Event\EventManager

返回 Cake\Event\EventManager 的全局可用实例,这用于分派从其他管理器创建范围之外附加的事件。通常用于创建钩子系统或类间通信

如果使用第一个参数调用,它将被设置为全局可用实例

参数
Cake\Event\EventManager|null $manager optional

事件管理器实例。

返回
Cake\Event\EventManager

isTrackingEvents() ¶ public

isTrackingEvents(): bool

返回此管理器是否设置为跟踪事件

返回
bool

listeners() ¶ public

listeners(string $eventKey): array

返回特定事件的全部监听器,按调用顺序排列

参数
string $eventKey
返回
array

matchingListeners() ¶ public

matchingListeners(string $eventKeyPattern): array

返回与指定模式匹配的监听器

参数
string $eventKeyPattern

要匹配的模式。

返回
array

normalizeHandler() ¶ protected

normalizeHandler(Cake\Event\EventListenerInterface $subscriber, Closure|array|string $handler): array

构建单个标准化处理程序。

标准化处理程序是一个包含以下键的数组

  • callable - 事件处理程序闭包
    • settings - 事件处理程序设置
参数
Cake\Event\EventListenerInterface $subscriber

事件订阅者

Closure|array|string $handler

事件处理程序

返回
array

normalizeHandlers() ¶ protected

normalizeHandlers(Cake\Event\EventListenerInterface $subscriber, Closure|array|string $handlers): array

构建标准化处理程序数组。

标准化处理程序是一个包含以下键的数组

  • callable - 事件处理程序闭包
    • settings - 事件处理程序设置
参数
Cake\Event\EventListenerInterface $subscriber

事件订阅者

Closure|array|string $handlers

事件处理程序

返回
array

off() ¶ public

off(Cake\Event\EventListenerInterface|callable|string $eventKey, Cake\Event\EventListenerInterface|callable|null $callable = null): $this

从活动监听器中删除监听器。

完全删除 EventListenerInterface

$manager->off($listener);

删除给定事件的全部监听器

$manager->off('My.event');

删除特定监听器

$manager->off('My.event', $callback);

从所有事件中删除回调

$manager->off($callback);
参数
Cake\Event\EventListenerInterface|callable|string $eventKey
Cake\Event\EventListenerInterface|callable|null $callable optional
返回
$this

on() ¶ public

on(Cake\Event\EventListenerInterface|string $eventKey, callable|array $options = [], callable|null $callable = null): $this

将新监听器添加到事件。

一个可变参数接口,用于添加模拟 jQuery.on() 的监听器。

绑定 EventListenerInterface

$eventManager->on($listener);

无选项绑定

$eventManager->on('Model.beforeSave', $callable);

使用选项绑定

$eventManager->on('Model.beforeSave', ['priority' => 90], $callable);
参数
Cake\Event\EventListenerInterface|string $eventKey
callable|array $options optional
callable|null $callable optional
返回
$this

prioritisedListeners() ¶ public

prioritisedListeners(string $eventKey): array

返回指定事件键的监听器,按优先级索引

参数
string $eventKey

事件键。

返回
array

setEventList() ¶ public

setEventList(Cake\Event\EventList $eventList): $this

启用分派事件的列表。

参数
Cake\Event\EventList $eventList

要使用的事件列表对象。

返回
$this

trackEvents() ¶ public

trackEvents(bool $enabled): $this

在运行时启用/禁用事件跟踪。

参数
bool $enabled

启用/禁用它,值为真或假。

返回
$this

unsetEventList() ¶ public

unsetEventList(): $this

禁用分派事件的列表。

返回
$this

属性详情

$_eventList ¶ protected

事件列表对象。

类型
Cake\Event\EventList|null

$_generalManager ¶ protected static

全局可用的实例,用于分派从任何范围附加的事件

类型
Cake\Event\EventManager|null

$_isGlobal ¶ protected

内部标志,用于区分通用管理器和单例

类型
bool

$_listeners ¶ protected

与之关联的监听器回调列表

类型
array

$_trackEvents ¶ protected

如果存在事件列表对象,则启用将事件自动添加到事件列表对象中。

类型
bool

$defaultPriority ¶ public static

新附加的监听器的默认优先级队列值

类型
int
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 手册
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识 & 商标
  • 社区
  • 参与进来
  • 问题 (Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 通讯
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助 & 支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成