1 | <?php |
||
42 | trait RelativeFileSearchTrait |
||
43 | { |
||
44 | /** |
||
45 | * Fluent interface setter for $relativeBaseDir. |
||
46 | * |
||
47 | * @param string $value MUST have a trailing directory separator and SHOULD be an absolute path. |
||
48 | * |
||
49 | * @return RelativeFileSearchTrait Fluent interface. |
||
|
|||
50 | */ |
||
51 | 25 | public function setRelativeBaseDir(string $value): self |
|
56 | /** |
||
57 | * Used to find a file relative to the base path using prefix, name, and suffix parts in varies ways. |
||
58 | * |
||
59 | * @param string $prefix Used as subdirectory or as part of file name. |
||
60 | * @param string $name Used as part of file names only. |
||
61 | * @param string $suffix Used as last part of file name or by self as file name. Think file extension without |
||
62 | * leading dot. |
||
63 | * |
||
64 | * @return string |
||
65 | * @throws \DomainException |
||
66 | * @throws \InvalidArgumentException |
||
67 | * @throws \LogicException |
||
68 | * @throws \Yapeal\Exception\YapealFileSystemException |
||
69 | */ |
||
70 | 21 | protected function findRelativeFileWithPath(string $prefix, string $name, string $suffix): string |
|
95 | /** |
||
96 | * Getter for $relativeBaseDir. |
||
97 | * |
||
98 | * @return string |
||
99 | * @throws \LogicException |
||
100 | */ |
||
101 | 21 | private function getRelativeBaseDir(): string |
|
109 | /** |
||
110 | * Holds the path that is prepended for searches. |
||
111 | * |
||
112 | * @var string $relativeBaseDir |
||
113 | */ |
||
114 | private $relativeBaseDir; |
||
115 | } |
||
116 |
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.