1 | <?php |
||
31 | class CommandFileDiscovery |
||
32 | { |
||
33 | protected $excludeList; |
||
34 | protected $searchLocations; |
||
35 | protected $searchPattern = '*Commands.php'; |
||
36 | protected $includeFilesAtBase = true; |
||
37 | |||
38 | public function __construct() |
||
46 | |||
47 | /** |
||
48 | * Specify whether to search for files at the base directory |
||
49 | * ($directoryList parameter to discover and discoverNamespaced |
||
50 | * methods), or only in the directories listed in the search paths. |
||
51 | * |
||
52 | * @param type $includeFilesAtBase |
||
53 | */ |
||
54 | public function setIncludeFilesAtBase($includeFilesAtBase) |
||
59 | |||
60 | /** |
||
61 | * Set the list of excludes to add to the finder, replacing |
||
62 | * whatever was there before. |
||
63 | * |
||
64 | * @param array $excludeList The list of directory names to skip when |
||
65 | * searching for command files. |
||
66 | */ |
||
67 | public function setExcludeList($excludeList) |
||
72 | |||
73 | /** |
||
74 | * Add one more location to the exclude list. |
||
75 | * |
||
76 | * @param string $exclude One directory name to skip when searching |
||
77 | * for command files. |
||
78 | */ |
||
79 | public function addExclude($exclude) |
||
84 | |||
85 | /** |
||
86 | * Set the list of search locations to examine in each directory where |
||
87 | * command files may be found. This replaces whatever was there before. |
||
88 | * |
||
89 | * @param array $searchLocations The list of locations to search for command files. |
||
90 | */ |
||
91 | public function setSearchLocations($searchLocations) |
||
96 | |||
97 | /** |
||
98 | * Add one more location to the search location list. |
||
99 | * |
||
100 | * @param string $location One more relative path to search |
||
101 | * for command files. |
||
102 | */ |
||
103 | public function addSearchLocation($location) |
||
108 | |||
109 | /** |
||
110 | * Specify the pattern / regex used by the finder to search for |
||
111 | * command files. |
||
112 | */ |
||
113 | public function setSearchPattern($searchPattern) |
||
118 | |||
119 | /** |
||
120 | * Given a list of directories, e.g. Drupal modules like: |
||
121 | * |
||
122 | * core/modules/block |
||
123 | * core/modules/dblog |
||
124 | * modules/default_content |
||
125 | * |
||
126 | * Discover command files in any of these locations. |
||
127 | * |
||
128 | * @param string|string[] $directoryList Places to search for commands. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | public function discoverNamespaced($directoryList, $baseNamespace = '') |
||
136 | |||
137 | /** |
||
138 | * Given a simple list containing paths to directories, where |
||
139 | * the last component of the path should appear in the namespace, |
||
140 | * after the base namespace, this function will return an |
||
141 | * associative array mapping the path's basename (e.g. the module |
||
142 | * name) to the directory path. |
||
143 | * |
||
144 | * Module names must be unique. |
||
145 | * |
||
146 | * @param string[] $directoryList A list of module locations |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | public function convertToNamespacedList($directoryList) |
||
158 | |||
159 | /** |
||
160 | * Search for command files in the specified locations. This is the function that |
||
161 | * should be used for all locations that are NOT modules of a framework. |
||
162 | * |
||
163 | * @param string|string[] $directoryList Places to search for commands. |
||
164 | * @return array |
||
165 | */ |
||
166 | public function discover($directoryList, $baseNamespace = '') |
||
179 | |||
180 | /** |
||
181 | * Search for command files in specific locations within a single directory. |
||
182 | * |
||
183 | * In each location, we will accept only a few places where command files |
||
184 | * can be found. This will reduce the need to search through many unrelated |
||
185 | * files. |
||
186 | * |
||
187 | * The valid search locations include: |
||
188 | * |
||
189 | * . |
||
190 | * CliTools |
||
191 | * src/CliTools |
||
192 | * |
||
193 | * The pattern we will look for is any file whose name ends in 'Commands.php'. |
||
194 | * A list of paths to found files will be returned. |
||
195 | */ |
||
196 | protected function discoverCommandFiles($directory, $baseNamespace) |
||
215 | |||
216 | /** |
||
217 | * Search for command files in just one particular location. Returns |
||
218 | * an associative array mapping from the pathname of the file to the |
||
219 | * classname that it contains. The pathname may be ignored if the search |
||
220 | * location is included in the autoloader. |
||
221 | * |
||
222 | * @param string $directory The location to search |
||
223 | * @param string $depth How deep to search (e.g. '== 0' or '< 2') |
||
224 | * @param string $baseNamespace Namespace to prepend to each classname |
||
225 | * |
||
226 | * @return array |
||
227 | */ |
||
228 | protected function discoverCommandFilesInLocation($directory, $depth, $baseNamespace) |
||
249 | |||
250 | /** |
||
251 | * Create a Finder object for use in searching a particular directory |
||
252 | * location. |
||
253 | * |
||
254 | * @param string $directory The location to search |
||
255 | * @param string $depth The depth limitation |
||
256 | * |
||
257 | * @return Finder |
||
258 | */ |
||
259 | protected function createFinder($directory, $depth) |
||
273 | |||
274 | /** |
||
275 | * Combine the items of the provied array into a backslash-separated |
||
276 | * namespace string. Empty and numeric items are omitted. |
||
277 | * |
||
278 | * @param array $namespaceParts List of components of a namespace |
||
279 | * |
||
280 | * @return string |
||
281 | */ |
||
282 | protected function joinNamespace(array $namespaceParts) |
||
292 | |||
293 | /** |
||
294 | * Combine the items of the provied array into a slash-separated |
||
295 | * pathname. Empty items are omitted. |
||
296 | * |
||
297 | * @param array $pathParts List of components of a path |
||
298 | * |
||
299 | * @return string |
||
300 | */ |
||
301 | protected function joinPaths(array $pathParts) |
||
311 | |||
312 | /** |
||
313 | * Simple wrapper around implode and array_filter. |
||
314 | * |
||
315 | * @param string $delimiter |
||
316 | * @param array $parts |
||
317 | * @param callable $filterFunction |
||
318 | */ |
||
319 | protected function joinParts($delimiter, $parts, $filterFunction) |
||
326 | } |
||
327 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..