-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileTenantLoader.php
More file actions
executable file
·55 lines (45 loc) · 1.24 KB
/
Copy pathFileTenantLoader.php
File metadata and controls
executable file
·55 lines (45 loc) · 1.24 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
<?php
class FileTenantLoader
{
private string $filePath;
private array $tenants = [];
public function __construct(string $filePath)
{
if (!is_readable($filePath)) {
throw new RuntimeException("Cannot read file: {$filePath}");
}
$this->filePath = $filePath;
}
/**
* Load and normalize Avature tenants from file
*
* @return array<string> List of base tenant URLs
*/
public function load(): array
{
$handle = fopen($this->filePath, 'r');
while (($line = fgets($handle)) !== false) {
$line = trim($line);
if ($line === '') continue;
$tenant = $this->extractTenant($line);
if ($tenant) {
$this->tenants[] = $tenant;
}
}
fclose($handle);
return array_values(array_unique($this->tenants));
}
/**
* Extract base tenant URL from any Avature link
*
* @param string $url
* @return string|null
*/
private function extractTenant(string $url): ?string
{
if (!preg_match('#https?://([a-z0-9\-]+\.avature\.net)#i', $url, $m)) {
return null;
}
return 'https://' . strtolower($m[1]);
}
}