Skip to content

Commit

Permalink
Allow all Pager queries by default
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Aug 18, 2023
1 parent 135f701 commit bcda539
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/Model.php
Expand Up @@ -167,9 +167,9 @@ abstract class Model implements ModelInterface
*/
protected string $pagerQuery;
/**
* @var array<string>
* @var array<string>|null
*/
protected array $pagerAllowedQueries;
protected array | null $pagerAllowedQueries = null;
/**
* Pager URL.
*
Expand Down Expand Up @@ -537,10 +537,7 @@ protected function setPager(Pager $pager) : static
if (isset($temp)) {
$pager->setUrl($temp);
}
$temp = $this->getPagerAllowedQueries();
if (isset($temp)) {
$pager->setAllowedQueries($temp);
}
$pager->setAllowedQueries($this->getPagerAllowedQueries());
$temp = $this->getPagerView();
if (isset($temp)) {
$pager->setDefaultView($temp);
Expand Down Expand Up @@ -586,7 +583,7 @@ protected function getPagerQuery() : ?string
*/
protected function getPagerAllowedQueries() : ?array
{
return $this->pagerAllowedQueries ?? null;
return $this->pagerAllowedQueries;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/ModelMock.php
Expand Up @@ -24,7 +24,7 @@ class ModelMock extends Model
public string $pagerView;
public string $pagerUrl;
public string $pagerQuery;
public array $pagerAllowedQueries;
public array | null $pagerAllowedQueries = null;

public function convertCase(string $value, string $case) : string
{
Expand Down
5 changes: 5 additions & 0 deletions tests/ModelTest.php
Expand Up @@ -542,6 +542,11 @@ public function testPagerQuery() : void
public function testPagerAllowedQueries() : void
{
$_SERVER['REQUEST_URI'] = '/products?page=5&foo=bar&order=asc&bla=bla&per_page=10';
$this->model->paginate(5);
self::assertSame(
'http://localhost:8080/products?page=5&foo=bar&order=asc&bla=bla&per_page=10',
$this->model->getPager()->getCurrentPageUrl()
);
$this->model->pagerAllowedQueries = ['order', 'per_page'];
$this->model->paginate(5);
self::assertSame(
Expand Down

0 comments on commit bcda539

Please sign in to comment.