64 lines
1.7 KiB
PHP
64 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';
|
|
}
|
|
}
|