Skip to content

Commit 317a73a

Browse files
authored
Fixes #17336: Fixed wildcard matching in Event::hasHandlers()
1 parent 2ca8da0 commit 317a73a

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Diff for: framework/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Yii Framework 2 Change Log
77
- Bug #16509: Fixed console command help text wordwrap for multi-byte strings (alexkart)
88
- Bug #17299: Fixed adding of input error class in `\yii\widgets\ActiveField::widget` (alexkart)
99
- Bug #17328: Added mime aliases for BMP and SVG files (cmoeke)
10+
- Bug #17336: Fixed wildcard matching in Event::hasHandlers() (samdark)
1011

1112

1213
2.0.19 May 21, 2019

Diff for: framework/base/Event.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ class_implements($class, true)
225225
);
226226

227227
// regular events
228-
foreach ($classes as $class) {
229-
if (!empty(self::$_events[$name][$class])) {
228+
foreach ($classes as $className) {
229+
if (!empty(self::$_events[$name][$className])) {
230230
return true;
231231
}
232232
}
@@ -240,8 +240,8 @@ class_implements($class, true)
240240
if (empty($handlers)) {
241241
continue;
242242
}
243-
foreach ($classes as $class) {
244-
if (!StringHelper::matchWildcard($classWildcard, $class)) {
243+
foreach ($classes as $className) {
244+
if (StringHelper::matchWildcard($classWildcard, $className, ['escape' => false])) {
245245
return true;
246246
}
247247
}

Diff for: tests/framework/base/EventTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ public function testHasHandlers()
9191
$this->assertTrue(Event::hasHandlers('yiiunit\framework\base\SomeInterface', SomeInterface::EVENT_SUPER_EVENT));
9292
}
9393

94+
/**
95+
* @see https://github.com/yiisoft/yii2/issues/17336
96+
*/
97+
public function testHasHandlersWithWildcard()
98+
{
99+
Event::on('\yiiunit\framework\base\*', 'save.*', function ($event) {
100+
// do nothing
101+
});
102+
103+
$this->assertTrue(Event::hasHandlers('yiiunit\framework\base\SomeInterface', 'save.it'), 'save.it');
104+
}
105+
94106
public function testOffUnmatchedHandler()
95107
{
96108
$this->assertFalse(Event::hasHandlers(Post::className(), 'afterSave'));

0 commit comments

Comments
 (0)