|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ZfTable ( Module for Zend Framework 2) |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2013 Piotr Duda [email protected] |
|
6
|
|
|
* @license MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace ZfTable\Source; |
|
10
|
|
|
|
|
11
|
|
|
use ZfTable\AbstractCommon; |
|
12
|
|
|
use ZfTable\Source\SourceInterface; |
|
13
|
|
|
|
|
14
|
|
|
abstract class AbstractSource extends AbstractCommon implements SourceInterface |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* |
|
19
|
|
|
* @var \ZfTable\Params\AdapterInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $paramAdapter; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
abstract protected function order(); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return \ZfTable\Params\AdapterInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getParamAdapter() |
|
30
|
|
|
{ |
|
31
|
|
|
if (!$this->paramAdapter) { |
|
32
|
|
|
$this->paramAdapter = $this->getTable()->getParamAdapter(); |
|
33
|
|
|
} |
|
34
|
|
|
return $this->paramAdapter; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* |
|
39
|
|
|
* @return \Zend\Paginator\Paginator |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getData() |
|
42
|
|
|
{ |
|
43
|
|
|
$paginator = $this->getPaginator(); |
|
44
|
|
|
return $paginator; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Init query like ordering and quick searching |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function initQuery() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->order(); |
|
54
|
|
|
$this->quickSearch(); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Init paginator |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function initPaginator() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->paginator->setItemCountPerPage($this->getParamAdapter()->getItemCountPerPage()); |
|
|
|
|
|
|
63
|
|
|
$this->paginator->setCurrentPageNumber($this->getParamAdapter()->getPage()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* |
|
68
|
|
|
* @param \Zend\Paginator\Paginator $paginator |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setPaginator(\Zend\Paginator\Paginator $paginator) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->paginator = $paginator; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* |
|
77
|
|
|
* @param \ZfTable\Params\AdapterInterface $paramAdapter |
|
78
|
|
|
*/ |
|
79
|
|
|
public function setParamAdapter(\ZfTable\Params\AdapterInterface $paramAdapter) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->paramAdapter = $paramAdapter; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: