Skip to content

Commit

Permalink
Rename methods to allow passing multiple events to optimize at once.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell committed Jul 31, 2023
1 parent 81f7318 commit 8a802d9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions benchmarks/CompiledProviderBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions src/ProviderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<class-string>
*/
public function optimizedEvents(): array
public function getOptimizedEvents(): array
{
return $this->optimizedEvents;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ProviderCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion tests/CompiledListenerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 8a802d9

Please sign in to comment.