1 | <?php |
||
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() |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | * @return \Zend\Paginator\Paginator |
||
40 | */ |
||
41 | public function getData() |
||
46 | |||
47 | |||
48 | /** |
||
49 | * Init query like ordering and quick searching |
||
50 | */ |
||
51 | protected function initQuery() |
||
56 | |||
57 | /** |
||
58 | * Init paginator |
||
59 | */ |
||
60 | protected function initPaginator() |
||
65 | |||
66 | /** |
||
67 | * |
||
68 | * @param \Zend\Paginator\Paginator $paginator |
||
69 | */ |
||
70 | public function setPaginator(\Zend\Paginator\Paginator $paginator) |
||
74 | |||
75 | /** |
||
76 | * |
||
77 | * @param \ZfTable\Params\AdapterInterface $paramAdapter |
||
78 | */ |
||
79 | public function setParamAdapter(\ZfTable\Params\AdapterInterface $paramAdapter) |
||
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: