当前位置: 首页>>代码示例>>PHP>>正文


PHP sfEventDispatcher::hasListeners方法代码示例

本文整理汇总了PHP中sfEventDispatcher::hasListeners方法的典型用法代码示例。如果您正苦于以下问题:PHP sfEventDispatcher::hasListeners方法的具体用法?PHP sfEventDispatcher::hasListeners怎么用?PHP sfEventDispatcher::hasListeners使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfEventDispatcher的用法示例。


在下文中一共展示了sfEventDispatcher::hasListeners方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sfEventDispatcher

$t = new lime_test(19);
$dispatcher = new sfEventDispatcher();
// ->connect() ->disconnect()
$t->diag('->connect() ->disconnect()');
$dispatcher->connect('bar', 'listenToBar');
$t->is($dispatcher->getListeners('bar'), array('listenToBar'), '->connect() connects a listener to an event name');
$dispatcher->connect('bar', 'listenToBarBar');
$t->is($dispatcher->getListeners('bar'), array('listenToBar', 'listenToBarBar'), '->connect() can connect several listeners for the same event name');
$dispatcher->connect('barbar', 'listenToBarBar');
$dispatcher->disconnect('bar', 'listenToBarBar');
$t->is($dispatcher->getListeners('bar'), array('listenToBar'), '->disconnect() disconnects a listener for an event name');
$t->is($dispatcher->getListeners('barbar'), array('listenToBarBar'), '->disconnect() disconnects a listener for an event name');
$t->ok($dispatcher->disconnect('foobar', 'listen') === false, '->disconnect() returns false if the listener does not exist');
// ->getListeners() ->hasListeners()
$t->diag('->getListeners() ->hasListeners()');
$t->is($dispatcher->hasListeners('foo'), false, '->hasListeners() returns false if the event has no listener');
$dispatcher->connect('foo', 'listenToFoo');
$t->is($dispatcher->hasListeners('foo'), true, '->hasListeners() returns true if the event has some listeners');
$dispatcher->disconnect('foo', 'listenToFoo');
$t->is($dispatcher->hasListeners('foo'), false, '->hasListeners() returns false if the event has no listener');
$t->is($dispatcher->getListeners('bar'), array('listenToBar'), '->getListeners() returns an array of listeners connected to the given event name');
$t->is($dispatcher->getListeners('foobar'), array(), '->getListeners() returns an empty array if no listener are connected to the given event name');
$listener = new Listener();
// ->notify()
$t->diag('->notify()');
$listener->reset();
$dispatcher = new sfEventDispatcher();
$dispatcher->connect('foo', array($listener, 'listenToFoo'));
$dispatcher->connect('foo', array($listener, 'listenToFooBis'));
$e = $dispatcher->notify($event = new sfEvent(new stdClass(), 'foo'));
$t->is($listener->getValue(), 'listenToFoolistenToFooBis', '->notify() notifies all registered listeners in order');
开发者ID:Phennim,项目名称:symfony1,代码行数:31,代码来源:sfEventDispatcherTest.php

示例2: dirname

/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id: sfLuceneEventConnectorTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(5, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
class FooListener
{
    public $event;
    public function listen($event)
    {
        $this->event = $event;
    }
}
$source = new sfEventDispatcher();
$target = new sfEventDispatcher();
$connector = new sfLuceneEventConnector($source, 'foo', $target, 'bar');
$t->ok($source->hasListeners('foo'), '__construct() connects a listener to the source');
$subject = 'Fabien';
$params = array('a', 'b', 'c');
$listener = new FooListener();
$target->connect('bar', array($listener, 'listen'));
$source->notify(new sfEvent($subject, 'foo', $params));
$t->isa_ok($listener->event, 'sfEvent', 'calling a linked event calls target');
$t->is($listener->event->getSubject(), $subject, 'calling a linked event sends correct subject');
$t->is($listener->event->getName(), 'bar', 'calling a linked event sends correct name');
$t->is($listener->event->getParameters(), $params, 'calling a linked event sends correct parameters');
开发者ID:palcoprincipal,项目名称:sfLucenePlugin,代码行数:31,代码来源:sfLuceneEventConnectorTest.php


注:本文中的sfEventDispatcher::hasListeners方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。