-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from alexpts/improve-speed
Improve speed
- Loading branch information
Showing
24 changed files
with
625 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PTS\Events; | ||
|
||
class EventEmitterExtraArgs implements EventEmitterInterface | ||
{ | ||
use EventEmitterExtraArgsTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PTS\Events; | ||
|
||
trait EventEmitterExtraArgsTrait | ||
{ | ||
use EventEmitterTrait; | ||
|
||
public function emit(string $name, array $args = []): void | ||
{ | ||
$countArgs = count($args); | ||
|
||
try { | ||
foreach ($this->listeners[$name] ?? [] as $i => $listener) { | ||
match ($countArgs) { | ||
0 => ($listener->handler)(...$listener->extraArgs), | ||
1 => ($listener->handler)($args[0], ...$listener->extraArgs), | ||
2 => ($listener->handler)($args[0], $args[1], ...$listener->extraArgs), | ||
default => ($listener->handler)(...$args, ...$listener->extraArgs), | ||
}; | ||
|
||
if ($listener->once) { | ||
unset($this->listeners[$name][$i]); | ||
if (count($this->listeners[$name]) === 0) { | ||
unset($this->listeners[$name]); | ||
} | ||
} | ||
} | ||
} catch (StopPropagation) { | ||
return; | ||
} | ||
} | ||
|
||
public function emitNoArgs(string $name): void | ||
{ | ||
try { | ||
foreach ($this->listeners[$name] ?? [] as $i => $listener) { | ||
($listener->handler)(...$listener->extraArgs); | ||
|
||
if ($listener->once) { | ||
unset($this->listeners[$name][$i]); | ||
if (count($this->listeners[$name]) === 0) { | ||
unset($this->listeners[$name]); | ||
} | ||
} | ||
} | ||
} catch (StopPropagation) { | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PTS\Events; | ||
|
||
class EventExtraArgsEmitter implements EventEmitterInterface | ||
{ | ||
use EventEmitterExtraArgsTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.