forked from urvishpatelce/lxd-app
fix: update code
This commit is contained in:
33
api/src/Utils/ContainerHelper.php
Normal file
33
api/src/Utils/ContainerHelper.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?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) : [];
|
||||
}
|
||||
}
|
||||
@ -3,19 +3,7 @@
|
||||
namespace App\Utils;
|
||||
|
||||
class LogWriterHelper {
|
||||
public static function write(string $name, string $uri): void {
|
||||
// Dynamically resolve the log directory relative to the current file
|
||||
$logDir = realpath(__DIR__ . '/../../public/last-access-logs');
|
||||
|
||||
// If the resolved path doesn't exist (e.g., public dir was missing), create it
|
||||
if (!$logDir) {
|
||||
$logDir = __DIR__ . '/../../public/last-access-logs';
|
||||
if (!file_exists($logDir)) {
|
||||
mkdir($logDir, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
$logLine = date("Y-m-d H:i:s") . " : " . $uri . "\n";
|
||||
file_put_contents($logDir . '/' . $name . '.txt', $logLine, FILE_APPEND);
|
||||
public static function write(string $name): void {
|
||||
touch($_ENV['STATEDIR']."/".$name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user