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