Files
MageSail/Magesail/Model/TunnelHostnameMatcher.php
T
2026-03-21 03:01:08 -05:00

45 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace MageSail\Magesail\Model;
use Magento\Framework\App\Request\Http;
/**
* Hostname-only tunnel detection against persisted tunnel base URLs (nginx global map without MageSail headers).
*/
class TunnelHostnameMatcher
{
public function __construct(
private readonly TunnelRegistry $tunnelRegistry
) {
}
/**
* When HTTP_HOST matches unsecure or secure tunnel base URL host, return the persisted store code.
*/
public function getStoreCodeIfRequestHostMatchesState(Http $request): ?string
{
$httpHost = $request->getServer('HTTP_HOST');
if ($httpHost === null || $httpHost === '') {
return null;
}
$match = $this->tunnelRegistry->findByRequestHost($httpHost);
if ($match === null) {
return null;
}
return (string) ($match['store_code'] ?? '');
}
public static function hostFromHttpHost(?string $httpHost): ?string
{
return TunnelRegistry::hostFromHttpHost($httpHost);
}
public static function hostFromBaseUrl(string $baseUrl): ?string
{
return TunnelRegistry::hostFromBaseUrl($baseUrl);
}
}