概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:42:06 | 135 次阅读 | 评论: 0 | 来源: 网络整理

The TraceableEventDispatcher is an event dispatcher that wraps any other event dispatcher and can then be used to determine which event listeners have been called by the dispatcher. Pass the event dispatcher to be wrapped and an instance of the Stopwatch to its constructor:

use SymfonyComponentEventDispatcherDebugTraceableEventDispatcher;
use SymfonyComponentStopwatchStopwatch;

// the event dispatcher to debug
$eventDispatcher = ...;

$traceableEventDispatcher = new TraceableEventDispatcher(
    $eventDispatcher,
    new Stopwatch()
);

Now, the TraceableEventDispatcher can be used like any other event dispatcher to register event listeners and dispatch events:

// ...

// register an event listener
$eventListener = ...;
$priority = ...;
$traceableEventDispatcher->addListener(
    'event.the_name',
    $eventListener,
    $priority
);

// dispatch an event
$event = ...;
$traceableEventDispatcher->dispatch('event.the_name', $event);

After your application has been processed, you can use the getCalledListeners() method to retrieve an array of event listeners that have been called in your application. Similarly, the getNotCalledListeners() method returns an array of event listeners that have not been called:

// ...

$calledListeners = $traceableEventDispatcher->getCalledListeners();
$notCalledListeners = $traceableEventDispatcher->getNotCalledListeners();
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务