1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
/** |
4
|
|
|
* Copyright (c) Phauthentic (https://github.com/Phauthentic) |
5
|
|
|
* |
6
|
|
|
* Licensed under The MIT License |
7
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
8
|
|
|
* Redistributions of files must retain the above copyright notice. |
9
|
|
|
* |
10
|
|
|
* @copyright Copyright (c) Phauthentic (https://github.com/Phauthentic) |
11
|
|
|
* @link https://github.com/Phauthentic |
12
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
13
|
|
|
*/ |
14
|
|
|
namespace Phauthentic\Pagination; |
15
|
|
|
|
16
|
|
|
use Phauthentic\Pagination\Paginator\PaginatorInterface; |
17
|
|
|
use Phauthentic\Pagination\ParamsFactory\PaginationParamsFactoryInterface; |
18
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Pagination Service |
22
|
|
|
* |
23
|
|
|
* Application layer pagination service that should in theory be able to paginate |
24
|
|
|
* any data / persistence layer implementation through the mappers. |
25
|
|
|
*/ |
26
|
|
|
class PaginationService |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Pagination Params Factory |
30
|
|
|
* |
31
|
|
|
* @var \Phauthentic\Pagination\PaginationParamsFactoryInterface |
|
|
|
|
32
|
|
|
*/ |
33
|
|
|
protected $paginationParamsFactory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Pagination to data layer implementation mapper |
37
|
|
|
* |
38
|
|
|
* @var \Phauthentic\Pagination\Paginator\PaginatorInterface; |
39
|
|
|
*/ |
40
|
|
|
protected $paginator; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor |
44
|
|
|
* |
45
|
|
|
* @param \Phauthentic\Pagination\PaginationParamsFactoryInterface |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
PaginationParamsFactoryInterface $paginationParamsFactory, |
49
|
|
|
PaginatorInterface $paginationAdapter |
50
|
|
|
) { |
51
|
|
|
$this->paginationParamsFactory = $paginationParamsFactory; |
|
|
|
|
52
|
|
|
$this->paginator = $paginationAdapter; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Sets the object that maps the pagination data to the underlying implementation |
57
|
|
|
* |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
|
|
public function setPaginator(PaginatorInterface $paginator): self |
61
|
|
|
{ |
62
|
|
|
$this->paginator = $paginator; |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Sets the pagination params factory |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function setPaginationParamsFactory(PaginationParamsFactoryInterface $factory): self |
73
|
|
|
{ |
74
|
|
|
$this->paginationParamsFactory = $factory; |
|
|
|
|
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Triggers the pagination |
81
|
|
|
* |
82
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface |
83
|
|
|
* @param mixed $repository The repository / array / collection to paginate |
84
|
|
|
* @param \Phauthentic\Pagination\PaginationParamsInterface $paginationParams Paging Params |
85
|
|
|
* @return mixed |
86
|
|
|
*/ |
87
|
|
|
public function paginate($repository, ?PaginationParamsInterface $paginationParams) |
88
|
|
|
{ |
89
|
|
|
if ($paginationParams === null) { |
90
|
|
|
$paginationParams = $this->paginationParamsFactory->build($repository); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->paginator->paginate($repository, $paginationParams); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths