| 1 | <?php |
||
| 12 | trait HasPivotTable |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @return Connection |
||
| 17 | */ |
||
| 18 | 1 | public function getDB() |
|
| 22 | |||
| 23 | /** @noinspection PhpMissingParentCallCommonInspection |
||
| 24 | * @return string |
||
| 25 | */ |
||
| 26 | 2 | public function generateTable() |
|
| 30 | |||
| 31 | /** |
||
| 32 | * Builds the name of a has-and-belongs-to-many association table |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | 1 | public function generatePivotTable() |
|
| 36 | { |
||
| 37 | $tables = [ |
||
| 38 | 1 | $this->getManager()->getTable(), |
|
| 39 | 1 | $this->getWith()->getTable() |
|
| 40 | ]; |
||
| 41 | 1 | sort($tables); |
|
| 42 | |||
| 43 | 1 | return implode("_", $tables); |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param SelectQuery $query |
||
| 48 | */ |
||
| 49 | 1 | protected function hydrateQueryWithPivotConstraints($query) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @return mixed |
||
| 58 | */ |
||
| 59 | 1 | protected function getPivotFK() |
|
| 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
Idableprovides a methodequalsIdthat 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.