diff --git a/benchmarks/CompiledProviderBench.php b/benchmarks/CompiledProviderBench.php index 3708faa..96682d9 100644 --- a/benchmarks/CompiledProviderBench.php +++ b/benchmarks/CompiledProviderBench.php @@ -47,9 +47,7 @@ public static function createCompiledProvider(): void $priority->next(); } - foreach (static::$optimizeClasses as $class) { - $builder->optimizeEvent($class); - } + $builder->optimizeEvents(...static::$optimizeClasses); // Write the generated compiler out to a temp file. $out = fopen(static::$filename, 'w'); diff --git a/src/ProviderBuilder.php b/src/ProviderBuilder.php index 44e6975..ccf90ad 100644 --- a/src/ProviderBuilder.php +++ b/src/ProviderBuilder.php @@ -32,17 +32,17 @@ public function __construct() /** * Pre-specify an event class that should have an optimized listener list built. * - * @param class-string $event + * @param class-string ...$events */ - public function optimizeEvent(string $event): void + public function optimizeEvents(string ...$events): void { - $this->optimizedEvents[] = $event; + $this->optimizedEvents = [...$this->optimizedEvents, ...$events]; } /** * @return array */ - public function optimizedEvents(): array + public function getOptimizedEvents(): array { return $this->optimizedEvents; } diff --git a/src/ProviderCompiler.php b/src/ProviderCompiler.php index 4162151..89e283f 100644 --- a/src/ProviderCompiler.php +++ b/src/ProviderCompiler.php @@ -63,7 +63,7 @@ protected function writeOptimizedList(ProviderBuilder $listeners, $stream): void $listenerDefs = iterator_to_array($listeners, false); - foreach ($listeners->optimizedEvents() as $event) { + foreach ($listeners->getOptimizedEvents() as $event) { $ancestors = $this->classAncestors($event); fwrite($stream, $this->startOptimizedEntry($event)); diff --git a/tests/CompiledListenerProviderTest.php b/tests/CompiledListenerProviderTest.php index 702521b..d919f62 100644 --- a/tests/CompiledListenerProviderTest.php +++ b/tests/CompiledListenerProviderTest.php @@ -171,7 +171,7 @@ public function test_optimize_event(): void $builder->addListenerAfter('id-2', "{$ns}event_listener_three", 'id-3'); $builder->addListenerAfter('id-3', "{$ns}event_listener_four"); - $builder->optimizeEvent(CollectingEvent::class); + $builder->optimizeEvents(CollectingEvent::class); $provider = $this->makeProvider($builder, $container, $class, $namespace);