本文整理匯總了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));
}