Skip to content

Commit

Permalink
Make options a public property assigned by ref, to avoid more involve…
Browse files Browse the repository at this point in the history
…d reference handling
  • Loading branch information
mpdude committed Sep 20, 2024
1 parent 226ea4b commit 8fac657
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/Knp/Component/Pager/Event/BeforeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
*/
final class BeforeEvent extends Event
{
/**
* @var array<string, mixed>
*/
public array $options = [];

public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly ArgumentAccessInterface $argumentAccess,
private readonly ?Connection $connection = null,
private array &$options = [],
) {
}

Expand All @@ -30,11 +34,6 @@ public function getArgumentAccess(): ArgumentAccessInterface
return $this->argumentAccess;
}

public function &getOptions(): array
{
return $this->options;
}

public function getConnection(): ?Connection
{
return $this->connection;
Expand Down
3 changes: 2 additions & 1 deletion src/Knp/Component/Pager/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function paginate($target, int $page = 1, ?int $limit = null, array $opti
}

// before pagination start
$beforeEvent = new Event\BeforeEvent($this->eventDispatcher, $this->argumentAccess, $this->connection, $options);
$beforeEvent = new Event\BeforeEvent($this->eventDispatcher, $this->argumentAccess, $this->connection);
$beforeEvent->options =& $options;
$this->eventDispatcher->dispatch($beforeEvent, 'knp_pager.before');
// items
$itemsEvent = new Event\ItemsEvent($offset, $limit);
Expand Down

0 comments on commit 8fac657

Please sign in to comment.