Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.7] Ensure the original paginator options are stored. #27273

Merged
merged 2 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Illuminate/Pagination/AbstractPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ abstract class AbstractPaginator implements Htmlable
*/
public $onEachSide = 3;

/**
* The paginator options.
*
* @var array
*/
protected $options;

/**
* The current path resolver callback.
*
Expand Down Expand Up @@ -563,6 +570,16 @@ public function setCollection(Collection $collection)
return $this;
}

/**
* Get the paginator options.
*
* @return array
*/
public function getOptions()
{
return $this->options;
}

/**
* Determine if the given item exists.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Pagination/LengthAwarePaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class LengthAwarePaginator extends AbstractPaginator implements Arrayable, Array
*/
public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])
{
$this->options = $options;

foreach ($options as $key => $value) {
$this->{$key} = $value;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Pagination/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Cou
*/
public function __construct($items, $perPage, $currentPage = null, array $options = [])
{
$this->options = $options;

foreach ($options as $key => $value) {
$this->{$key} = $value;
}
Expand Down
15 changes: 13 additions & 2 deletions tests/Pagination/LengthAwarePaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
class LengthAwarePaginatorTest extends TestCase
{
/**
* @var LengthAwarePaginator
* @var \Illuminate\Pagination\LengthAwarePaginator
*/
private $p;

/**
* @var array
*/
private $options;

public function setUp()
{
$this->p = new LengthAwarePaginator($array = ['item1', 'item2', 'item3', 'item4'], 4, 2, 2);
$this->options = ['onEachSide' => 5];
$this->p = new LengthAwarePaginator($array = ['item1', 'item2', 'item3', 'item4'], 4, 2, 2, $this->options);
}

public function tearDown()
Expand Down Expand Up @@ -97,4 +103,9 @@ public function testLengthAwarePaginatorCorrectlyGenerateUrlsWithQueryAndSpaces(
$this->assertEquals('http://website.com?key=value%20with%20spaces&foo=2',
$this->p->url($this->p->currentPage()));
}

public function testItRetrievesThePaginatorOptions()
{
$this->assertSame($this->options, $this->p->getOptions());
}
}
8 changes: 8 additions & 0 deletions tests/Pagination/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ public function testPaginatorGeneratesUrlsWithoutTrailingSlash()

$this->assertEquals('http://website.com/test?page=1', $p->previousPageUrl());
}

public function testItRetrievesThePaginatorOptions()
{
$p = new Paginator($array = ['item1', 'item2', 'item3'], 2, 2,
$options = ['path' => 'http://website.com/test']);

$this->assertSame($p->getOptions(), $options);
}
}