1 | <?php |
||
28 | trait WrappedCommandTrait |
||
29 | { |
||
30 | /** |
||
31 | * The current composer instance. |
||
32 | * |
||
33 | * @var Composer |
||
34 | */ |
||
35 | private $composer; |
||
36 | |||
37 | /** |
||
38 | * The factory method to use for creating a composer instance. |
||
39 | * |
||
40 | * @var \Closure |
||
41 | */ |
||
42 | private $composerFactory; |
||
43 | |||
44 | /** |
||
45 | * Retrieve the composer instance. |
||
46 | * |
||
47 | * @param bool $required Flag if the instance is required. |
||
48 | * |
||
49 | * @param bool $disablePlugins Flag if plugins shall get disabled. |
||
50 | * |
||
51 | * @return Composer|null |
||
52 | * |
||
53 | * @throws \RuntimeException When no factory closure has been set. |
||
54 | */ |
||
55 | public function getComposer($required = true, $disablePlugins = false) |
||
72 | |||
73 | /** |
||
74 | * Save the composer instance to use. |
||
75 | * |
||
76 | * @param Composer $composer The instance to use. |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | public function setComposer(Composer $composer) |
||
84 | |||
85 | /** |
||
86 | * Removes the cached composer instance. |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | public function resetComposer() |
||
94 | |||
95 | /** |
||
96 | * Set the composer factory closure. |
||
97 | * |
||
98 | * @param \Closure $composerFactory The new factory function. |
||
99 | * |
||
100 | * @return WrappedCommandTrait |
||
|
|||
101 | */ |
||
102 | public function setComposerFactory($composerFactory) |
||
108 | } |
||
109 |
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.