Files
MageSail/Magesail/Model/TunnelHostnameMatcher.php
T
snxraven cc456a4cfa feat(magesail): multi-tunnel registry, per-tunnel stores, and admin UX
- Add TunnelRegistry (var/magesail_tunnels.json) and TunnelProcessPaths;
  migrate legacy magesail_tunnel_store.json and PID/key files
- Provision unique store codes per tunnel; website/group selection;
  stop vs remove; per-tunnel NGINX map, cron, status/logtail
- Fix log path: use DirectoryList::LOG (not LOG_DIR)
- Ignore missing store codes for MAGE_RUN_* (stale nginx / magesail_tunnel)
- Allow duplicate local ports; Admin port presets 443/80/8080 + custom;
  update docs and system.xml comments
2026-03-21 00:49:07 -05:00

44 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);
}
}