當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EventManager::matchingListeners方法代碼示例

本文整理匯總了PHP中Cake\Event\EventManager::matchingListeners方法的典型用法代碼示例。如果您正苦於以下問題:PHP EventManager::matchingListeners方法的具體用法?PHP EventManager::matchingListeners怎麽用?PHP EventManager::matchingListeners使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Event\EventManager的用法示例。


在下文中一共展示了EventManager::matchingListeners方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testMatchingListeners

 /**
  * Tests attached event listeners for matching key pattern
  *
  * @return void
  */
 public function testMatchingListeners()
 {
     $manager = new EventManager();
     $manager->attach('fakeFunction1', 'fake.event');
     $manager->attach('fakeFunction2', 'real.event');
     $manager->attach('fakeFunction3', 'test.event');
     $manager->attach('fakeFunction4', 'event.test');
     $this->assertArrayHasKey('fake.event', $manager->matchingListeners('fake.event'));
     $this->assertArrayHasKey('real.event', $manager->matchingListeners('real.event'));
     $this->assertArrayHasKey('test.event', $manager->matchingListeners('test.event'));
     $this->assertArrayHasKey('event.test', $manager->matchingListeners('event.test'));
     $this->assertArrayHasKey('fake.event', $manager->matchingListeners('fake'));
     $this->assertArrayHasKey('real.event', $manager->matchingListeners('real'));
     $this->assertArrayHasKey('test.event', $manager->matchingListeners('test'));
     $this->assertArrayHasKey('event.test', $manager->matchingListeners('test'));
     $this->assertArrayHasKey('fake.event', $manager->matchingListeners('event'));
     $this->assertArrayHasKey('real.event', $manager->matchingListeners('event'));
     $this->assertArrayHasKey('test.event', $manager->matchingListeners('event'));
     $this->assertArrayHasKey('event.test', $manager->matchingListeners('event'));
     $this->assertArrayHasKey('fake.event', $manager->matchingListeners('.event'));
     $this->assertArrayHasKey('real.event', $manager->matchingListeners('.event'));
     $this->assertArrayHasKey('test.event', $manager->matchingListeners('.event'));
     $this->assertArrayHasKey('test.event', $manager->matchingListeners('test.'));
     $this->assertArrayHasKey('event.test', $manager->matchingListeners('.test'));
     $this->assertEmpty($manager->matchingListeners('/test'));
     $this->assertEmpty($manager->matchingListeners('test/'));
     $this->assertEmpty($manager->matchingListeners('/test/'));
     $this->assertEmpty($manager->matchingListeners('test$'));
     $this->assertEmpty($manager->matchingListeners('ev.nt'));
     $this->assertEmpty($manager->matchingListeners('^test'));
     $this->assertEmpty($manager->matchingListeners('^event'));
     $this->assertEmpty($manager->matchingListeners('*event'));
     $this->assertEmpty($manager->matchingListeners('event*'));
     $this->assertEmpty($manager->matchingListeners('foo'));
     $expected = ['fake.event', 'real.event', 'test.event', 'event.test'];
     $result = $manager->matchingListeners('event');
     $this->assertNotEmpty($result);
     $this->assertSame($expected, array_keys($result));
     $expected = ['fake.event', 'real.event', 'test.event'];
     $result = $manager->matchingListeners('.event');
     $this->assertNotEmpty($result);
     $this->assertSame($expected, array_keys($result));
     $expected = ['test.event', 'event.test'];
     $result = $manager->matchingListeners('test');
     $this->assertNotEmpty($result);
     $this->assertSame($expected, array_keys($result));
     $expected = ['test.event'];
     $result = $manager->matchingListeners('test.');
     $this->assertNotEmpty($result);
     $this->assertSame($expected, array_keys($result));
     $expected = ['event.test'];
     $result = $manager->matchingListeners('.test');
     $this->assertNotEmpty($result);
     $this->assertSame($expected, array_keys($result));
 }
開發者ID:rashmi,項目名稱:newrepo,代碼行數:60,代碼來源:EventManagerTest.php


注:本文中的Cake\Event\EventManager::matchingListeners方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。