Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 29d9577

Browse files
committed
set target and params only if any
1 parent 9d10eec commit 29d9577

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/EventManager.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ public function trigger($eventName, $target = null, $argv = [])
132132
{
133133
$event = clone $this->eventPrototype;
134134
$event->setName($eventName);
135-
$event->setTarget($target);
136-
$event->setParams($argv);
135+
136+
if ($target !== null) {
137+
$event->setTarget($target);
138+
}
139+
140+
if ($argv) {
141+
$event->setParams($argv);
142+
}
137143

138144
return $this->triggerListeners($event);
139145
}
@@ -145,8 +151,14 @@ public function triggerUntil(callable $callback, $eventName, $target = null, $ar
145151
{
146152
$event = clone $this->eventPrototype;
147153
$event->setName($eventName);
148-
$event->setTarget($target);
149-
$event->setParams($argv);
154+
155+
if ($target !== null) {
156+
$event->setTarget($target);
157+
}
158+
159+
if ($argv) {
160+
$event->setParams($argv);
161+
}
150162

151163
return $this->triggerListeners($event, $callback);
152164
}
@@ -226,22 +238,21 @@ public function detach(callable $listener, $eventName = null, $force = false)
226238
break;
227239
}
228240
}
241+
}
229242

230-
// If the queue for the given event is empty, remove it.
231-
if (empty($this->events[$eventName])) {
232-
unset($this->events[$eventName]);
233-
break;
234-
}
243+
// If the queue for the given event is empty, remove it.
244+
if (empty($this->events[$eventName])) {
245+
unset($this->events[$eventName]);
235246
}
236247
}
237248

238249
/**
239250
* @inheritDoc
240251
*/
241-
public function clearListeners($event)
252+
public function clearListeners($eventName)
242253
{
243-
if (isset($this->events[$event])) {
244-
unset($this->events[$event]);
254+
if (isset($this->events[$eventName])) {
255+
unset($this->events[$eventName]);
245256
}
246257
}
247258

0 commit comments

Comments
 (0)