1 | <?php |
||
13 | trait HasPrimaryKeyTrait |
||
14 | { |
||
15 | /** |
||
16 | * @var null|string |
||
17 | */ |
||
18 | protected $primaryKey = null; |
||
19 | |||
20 | /** |
||
21 | * @param $params |
||
22 | */ |
||
23 | 3 | public function checkParamPrimaryKey($params) |
|
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | 5 | public function getPrimaryKey() |
|
42 | |||
43 | /** |
||
44 | * @param $name |
||
45 | */ |
||
46 | 5 | public function setPrimaryKey($name) |
|
50 | |||
51 | 5 | protected function initPrimaryKey() |
|
55 | |||
56 | /** |
||
57 | * @return string |
||
58 | */ |
||
59 | 5 | protected function generatePrimaryKey() |
|
63 | } |
||
64 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.