@@ 34-48 (lines=15) @@ | ||
31 | * @param mixed ...$args Arguments |
|
32 | * @return self |
|
33 | */ |
|
34 | public function event($name, ...$args) |
|
35 | { |
|
36 | if ($this->addThisToEvents) { |
|
37 | array_unshift($args, $this); |
|
38 | } |
|
39 | if (isset($this->eventHandlers[$name])) { |
|
40 | $this->lastEventName = $name; |
|
41 | foreach ($this->eventHandlers[$name] as $cb) { |
|
42 | if ($cb(...$args) === true) { |
|
43 | return $this; |
|
44 | } |
|
45 | } |
|
46 | } |
|
47 | return $this; |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * Propagate event |
|
@@ 56-70 (lines=15) @@ | ||
53 | * @param mixed ...$args Arguments |
|
54 | * @return self |
|
55 | */ |
|
56 | public function trigger($name, ...$args) |
|
57 | { |
|
58 | if ($this->addThisToEvents) { |
|
59 | array_unshift($args, $this); |
|
60 | } |
|
61 | if (isset($this->eventHandlers[$name])) { |
|
62 | $this->lastEventName = $name; |
|
63 | foreach ($this->eventHandlers[$name] as $cb) { |
|
64 | if ($cb(...$args) === true) { |
|
65 | return $this; |
|
66 | } |
|
67 | } |
|
68 | } |
|
69 | return $this; |
|
70 | } |
|
71 | ||
72 | /** |
|
73 | * Propagate event |