1 | <?php |
||
20 | trait RelationProvider |
||
21 | { |
||
22 | /** |
||
23 | * @param string|array ...$relations |
||
24 | * @return Query|$this|self |
||
25 | */ |
||
26 | public function with(...$relations): self |
||
35 | |||
36 | /** |
||
37 | * @param string|array ...$relations |
||
38 | * @return Query|$this|self |
||
39 | */ |
||
40 | public function join(...$relations): self |
||
41 | { |
||
42 | 1 | return $this->addRelation(function(string $field, \Closure $inner = null) { |
|
43 | 1 | return new Join($this, $field, Join::TYPE_JOIN, $inner); |
|
44 | 1 | }, ...$relations); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param string|array ...$relations |
||
49 | * @return Query|$this|self |
||
50 | */ |
||
51 | public function leftJoin(...$relations): self |
||
57 | |||
58 | /** |
||
59 | * @param string|array ...$relations |
||
60 | * @return Query|$this|self |
||
61 | */ |
||
62 | public function innerJoin(...$relations): self |
||
68 | |||
69 | /** |
||
70 | * @param \Closure $onCreate |
||
71 | * @param string|array ...$relations |
||
72 | * @return Query|$this|self |
||
73 | */ |
||
74 | 2 | private function addRelation(\Closure $onCreate, ...$relations): self |
|
100 | } |
||
101 |
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.