1 | <?php |
||
14 | trait HasDomTrait |
||
15 | { |
||
16 | /** @var DOMDocument $dom */ |
||
17 | private $dom; |
||
18 | |||
19 | /** |
||
20 | * @param $tagType |
||
21 | * @return DOMElement |
||
22 | */ |
||
23 | 21 | public function createElement($tagType) |
|
27 | |||
28 | /** |
||
29 | * @param $text |
||
30 | * @return DOMText |
||
31 | */ |
||
32 | 15 | public function createText($text) |
|
36 | |||
37 | /** |
||
38 | * @return DOMElement |
||
39 | */ |
||
40 | 2 | public function createLineBreak() |
|
44 | |||
45 | /** |
||
46 | * @return DOMDocument |
||
47 | */ |
||
48 | 40 | public function getDom() |
|
52 | |||
53 | /** |
||
54 | * @param DOMDocument $dom |
||
55 | * @return HasDomTrait |
||
|
|||
56 | */ |
||
57 | 40 | public function setDom($dom) |
|
62 | } |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.