本文整理匯總了PHP中JEventDispatcher::attach方法的典型用法代碼示例。如果您正苦於以下問題:PHP JEventDispatcher::attach方法的具體用法?PHP JEventDispatcher::attach怎麽用?PHP JEventDispatcher::attach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類JEventDispatcher
的用法示例。
在下文中一共展示了JEventDispatcher::attach方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testDetach
/**
* Test JEventDispatcher::detach().
*
* @since 11.3
*
* @return void
*/
public function testDetach()
{
// Adding 3 events to detach later
$observer1 = array('handler' => 'fakefunction', 'event' => 'onTestEvent');
$observer2 = array('handler' => 'JEventMockFunction', 'event' => 'onTestEvent');
$this->object->attach($observer2);
$observer3 = new JEventInspector($this->object);
$this->object->attach($observer3);
// Test removing a non-existing observer
$this->assertThat(TestReflection::getValue($this->object, '_methods'), $this->equalTo(array('ontestevent' => array(0, 1))));
$this->assertThat(TestReflection::getValue($this->object, '_observers'), $this->equalTo(array($observer2, $observer3)));
$return = $this->object->detach($observer1);
$this->assertFalse($return);
$this->assertThat(TestReflection::getValue($this->object, '_methods'), $this->equalTo(array('ontestevent' => array(0, 1))));
$this->assertThat(TestReflection::getValue($this->object, '_observers'), $this->equalTo(array($observer2, $observer3)));
// Test removing a functional observer
$return = $this->object->detach($observer2);
$this->assertTrue($return);
$this->assertThat(TestReflection::getValue($this->object, '_methods'), $this->equalTo(array('ontestevent' => array(1 => 1))));
$this->assertThat(TestReflection::getValue($this->object, '_observers'), $this->equalTo(array(1 => $observer3)));
// Test removing an object observer with more than one event
$return = $this->object->detach($observer3);
$this->assertTrue($return);
$this->assertThat(TestReflection::getValue($this->object, '_methods'), $this->equalTo(array('ontestevent' => array())));
$this->assertThat(TestReflection::getValue($this->object, '_observers'), $this->equalTo(array()));
}