forked from urvishpatelce/lxd-app
34 lines
869 B
PHP
34 lines
869 B
PHP
<?php
|
|
|
|
namespace App\Utils;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
class ContainerHelper
|
|
{
|
|
public static function getName(ServerRequestInterface $request): ?string
|
|
{
|
|
// Try to get Origin header, fallback to Host
|
|
$origin = $request->getHeaderLine('Origin');
|
|
$domain = !empty($origin) ? parse_url($origin, PHP_URL_HOST) : $request->getHeaderLine('Host');
|
|
|
|
// Load config.json once
|
|
$config = self::getConfig();
|
|
return $config[$domain] ?? null;
|
|
}
|
|
|
|
protected static function getConfig(): array
|
|
{
|
|
static $config = null;
|
|
|
|
if ($config !== null) {
|
|
return $config;
|
|
}
|
|
|
|
$configPath = __DIR__ . '/../../config.json';
|
|
|
|
return file_exists($configPath) ? json_decode(file_get_contents($configPath), true) : [];
|
|
}
|
|
}
|