1 | <?php |
||
20 | class ExampleFinder |
||
21 | { |
||
22 | /** @var string */ |
||
23 | private $sourceDirectory = ''; |
||
24 | |||
25 | /** @var string[] */ |
||
26 | private $exampleDirectories = array(); |
||
27 | |||
28 | /** |
||
29 | * Attempts to find the example contents for the given descriptor. |
||
30 | * |
||
31 | * @param Example $example |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | 1 | public function find(Example $example) |
|
46 | |||
47 | /** |
||
48 | * Registers the project's root directory where an 'examples' folder can be expected. |
||
49 | * |
||
50 | * @param string $directory |
||
51 | * |
||
52 | * @return void |
||
53 | */ |
||
54 | public function setSourceDirectory($directory = '') |
||
58 | |||
59 | /** |
||
60 | * Returns the project's root directory where an 'examples' folder can be expected. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 1 | public function getSourceDirectory() |
|
68 | |||
69 | /** |
||
70 | * Registers a series of directories that may contain examples. |
||
71 | * |
||
72 | * @param string[] $directories |
||
73 | */ |
||
74 | public function setExampleDirectories(array $directories) |
||
78 | |||
79 | /** |
||
80 | * Returns a series of directories that may contain examples. |
||
81 | * |
||
82 | * @return string[] |
||
83 | */ |
||
84 | public function getExampleDirectories() |
||
88 | |||
89 | /** |
||
90 | * Attempts to find the requested example file and returns its contents or null if no file was found. |
||
91 | * |
||
92 | * This method will try several methods in search of the given example file, the first one it encounters is |
||
93 | * returned: |
||
94 | * |
||
95 | * 1. Iterates through all examples folders for the given filename |
||
96 | * 2. Checks the source folder for the given filename |
||
97 | * 3. Checks the 'examples' folder in the current working directory for examples |
||
98 | * 4. Checks the path relative to the current working directory for the given filename |
||
99 | * |
||
100 | * @param string $filename |
||
101 | * |
||
102 | * @return string|null |
||
103 | */ |
||
104 | 1 | private function getExampleFileContents($filename) |
|
128 | |||
129 | /** |
||
130 | * Get example filepath based on the example directory inside your project. |
||
131 | * |
||
132 | * @param string $file |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | 1 | private function getExamplePathFromExampleDirectory($file) |
|
140 | |||
141 | /** |
||
142 | * Returns a path to the example file in the given directory.. |
||
143 | * |
||
144 | * @param string $directory |
||
145 | * @param string $file |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | private function constructExamplePath($directory, $file) |
||
153 | |||
154 | /** |
||
155 | * Get example filepath based on sourcecode. |
||
156 | * |
||
157 | * @param string $file |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | 1 | private function getExamplePathFromSource($file) |
|
170 | } |
||
171 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.