-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.php
More file actions
31 lines (29 loc) · 932 Bytes
/
Copy pathhelpers.php
File metadata and controls
31 lines (29 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* Takes the comma-separated setting value of paths, cleans any leading
* or trailing space, expands relative home references (`~/`) into
* absolute paths, and joins them back together into a glob search string
* using braces (`{/path/one,/path/two}/*`).
*
* @param string $settingValue
* @param string $homePath
* @return string
*/
function buildSearchPathString(string $settingValue, string $homePath): string
{
$searchPaths = array_map(static function($path) use ($homePath) {
$path = trim($path);
if (str_starts_with($path, '~/')) {
// Expand `~/` to full path
$fullHomePath = $homePath.'/';
return substr_replace(
$path,
$fullHomePath,
0,
strlen('~/')
);
}
return $path;
}, explode(',', $settingValue));
return '{'.implode(',', $searchPaths).'}/*';
}