Files
MageSail/Magesail/Model/TunnelProcessPaths.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

63 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace MageSail\Magesail\Model;
use Magento\Framework\App\Filesystem\DirectoryList;
/**
* Per-tunnel PID, key, and log file paths under var/.
*/
class TunnelProcessPaths
{
private const VAR_SUBDIR = 'magesail_tunnels';
public function __construct(
private readonly DirectoryList $directoryList
) {
}
public function getVarTunnelDir(): string
{
return $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/' . self::VAR_SUBDIR;
}
public function getPidFilePath(string $tunnelId): string
{
return $this->getVarTunnelDir() . '/' . $this->sanitizeId($tunnelId) . '.pid';
}
public function getKeyFilePath(string $tunnelId): string
{
return $this->getVarTunnelDir() . '/' . $this->sanitizeId($tunnelId) . '.key';
}
public function getLogFilePath(string $tunnelId): string
{
return $this->directoryList->getPath(DirectoryList::LOG) . '/magesail_tunnel_' . $this->sanitizeId($tunnelId) . '.log';
}
/**
* Legacy single-tunnel paths (pre multi-tunnel).
*/
public function getLegacyPidFilePath(): string
{
return $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/magesail.pid';
}
public function getLegacyKeyFilePath(): string
{
return $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/magesail.key';
}
public function getLegacyLogFilePath(): string
{
return $this->directoryList->getPath(DirectoryList::LOG) . '/magesail_tunnel.log';
}
private function sanitizeId(string $tunnelId): string
{
return preg_replace('/[^a-zA-Z0-9_-]/', '', $tunnelId) ?: 'invalid';
}
}