-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathUtils.php
More file actions
69 lines (59 loc) · 2.45 KB
/
Utils.php
File metadata and controls
69 lines (59 loc) · 2.45 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Fleetbase\Solid\Support;
use Fleetbase\Support\Utils as FleetbaseUtils;
use Illuminate\Support\Str;
class Utils extends FleetbaseUtils
{
/**
* Recursively searches through a nested array of pods and their contents
* to find an item that matches a given key-value pair.
*
* This function handles nested structures where each folder may contain
* additional folders and files. It returns the first matching item based
* on the specified key and value.
*
* @param array $data the array representing the pods and their nested contents
* @param string $key The key used to search items (e.g., 'name', 'id').
* @param string $value the value to match against the specified key
* @param bool $search whether to perform a search match with string contains
*
* @return mixed|null returns the first matching item found in the structure or
* `null` if no item is found that matches the criteria
*/
public static function searchPods(array $data = [], string $key, string $value, bool $search = false)
{
foreach ($data as $item) {
if ($search === false && data_get($item, $key) && strcasecmp(data_get($item, $key), $value) === 0) {
return $item;
}
if ($search === true && data_get($item, $key) && Str::contains(strtolower(data_get($item, $key)), strtolower($value))) {
return $item;
}
if (is_array(data_get($item, 'contents'))) {
$contentSearchResult = static::searchPods(data_get($item, 'contents', []), $key, $value);
if ($contentSearchResult) {
return $contentSearchResult;
}
}
}
return null;
}
/**
* Get the Solid server URL from configuration.
*
* Constructs the URL from individual server configuration components.
*
* @return string
*/
public static function getSolidServerUrl(): string
{
$host = config('solid.server.host', 'http://localhost');
$port = config('solid.server.port', 3000);
$secure = config('solid.server.secure', false);
// Remove protocol from host if present
$host = preg_replace('#^.*://#', '', $host);
// Construct URL with proper protocol
$protocol = $secure ? 'https' : 'http';
return "{$protocol}://{$host}:{$port}";
}
}