Skip to content

Commit 82e97a1

Browse files
Adds an adapter for simple paginator in laravel
1 parent ddcd5d6 commit 82e97a1

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHPOpenSourceSaver\Fractal package.
5+
*
6+
* (c) Phil Sturgeon <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace PHPOpenSourceSaver\Fractal\Pagination;
13+
14+
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
15+
16+
/**
17+
* A paginator adapter for illuminate/pagination.
18+
*
19+
* @author Maxime Beaudoin <[email protected]>
20+
* @author Marc Addeo <[email protected]>
21+
*/
22+
class IlluminateSimplePaginatorAdapter implements PaginatorInterface
23+
{
24+
protected LengthAwarePaginator $paginator;
25+
26+
/**
27+
* Create a new illuminate pagination adapter.
28+
*/
29+
public function __construct(LengthAwarePaginator $paginator)
30+
{
31+
$this->paginator = $paginator;
32+
}
33+
34+
/**
35+
* {@inheritDoc}
36+
*/
37+
public function getCurrentPage(): int
38+
{
39+
return $this->paginator->currentPage();
40+
}
41+
42+
/**
43+
* {@inheritDoc}
44+
*/
45+
public function getLastPage(): int
46+
{
47+
return $this->paginator->lastPage();
48+
}
49+
50+
/**
51+
* {@inheritDoc}
52+
*/
53+
public function getTotal(): int
54+
{
55+
return $this->paginator->total();
56+
}
57+
58+
/**
59+
* {@inheritDoc}
60+
*/
61+
public function getCount(): int
62+
{
63+
return $this->paginator->count();
64+
}
65+
66+
/**
67+
* {@inheritDoc}
68+
*/
69+
public function getPerPage(): int
70+
{
71+
return $this->paginator->perPage();
72+
}
73+
74+
/**
75+
* {@inheritDoc}
76+
*/
77+
public function getUrl(int $page): string
78+
{
79+
return $this->paginator->url($page);
80+
}
81+
82+
/**
83+
* Get the paginator instance.
84+
*/
85+
public function getPaginator(): LengthAwarePaginator
86+
{
87+
return $this->paginator;
88+
}
89+
}

0 commit comments

Comments
 (0)