1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Polder Knowledge / entityservice-zend-paginator (https://polderknowledge.com) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/polderknowledge/entityservice-zend-paginator for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2016 Polder Knowledge (https://polderknowledge.com) |
7
|
|
|
* @license https://github.com/polderknowledge/entityservice-zend-paginator/blob/master/LICENSE.md MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace PolderKnowledge\EntityService\Paginator\Adapter; |
11
|
|
|
|
12
|
|
|
use Doctrine\Common\Collections\Criteria; |
13
|
|
|
use PolderKnowledge\EntityService\EntityServiceInterface; |
14
|
|
|
use Zend\Paginator\Adapter\AdapterInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Paginator adapter for EntityServices |
18
|
|
|
*/ |
19
|
|
|
class EntityService implements AdapterInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* EntityService used to fetch adapter |
23
|
|
|
* |
24
|
|
|
* @var EntityServiceInterface |
25
|
|
|
*/ |
26
|
|
|
private $entityService; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Criteria used to fetch entities |
30
|
|
|
* |
31
|
|
|
* @var array|Criteria |
32
|
|
|
*/ |
33
|
|
|
private $criteria; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Creates a new instance of this class |
37
|
|
|
* |
38
|
|
|
* @param EntityServiceInterface $entityService |
39
|
|
|
* @param Criteria $criteria The criteria to match. |
40
|
|
|
* @param array $order |
|
|
|
|
41
|
|
|
*/ |
42
|
6 |
|
public function __construct(EntityServiceInterface $entityService, Criteria $criteria = null) |
43
|
|
|
{ |
44
|
6 |
|
$this->entityService = $entityService; |
45
|
6 |
|
$this->criteria = is_object($criteria) ? clone $criteria : Criteria::create(); |
46
|
6 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inhericDoc} |
50
|
|
|
* |
51
|
|
|
* @return int |
52
|
|
|
*/ |
53
|
3 |
|
public function count() |
54
|
|
|
{ |
55
|
3 |
|
return $this->entityService->countBy($this->criteria); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inhericDoc} |
60
|
|
|
* |
61
|
|
|
* @param int $offset Page offset |
62
|
|
|
* @param int $itemCountPerPage Number of items per page |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
3 |
|
public function getItems($offset, $itemCountPerPage) |
66
|
|
|
{ |
67
|
3 |
|
$this->criteria->setFirstResult($offset); |
68
|
3 |
|
$this->criteria->setMaxResults($itemCountPerPage); |
69
|
|
|
|
70
|
3 |
|
return $this->entityService->findBy($this->criteria); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.