Sindbad~EG File Manager
<?php
namespace App\Parser;
use Symfony\Component\Filesystem\Filesystem;
class ServerModeParser
{
/**
* @var string
*/
protected $configTypeSelectorFile;
/**
* @var Filesystem
*/
protected $fs;
/**
* @var array
*/
private $parsed;
/**
* @var string
*/
private $defaultServerMode;
private const AVAILABLE = ['apache', 'lsws', 'lsws-apache'];
public function __construct(string $configTypeSelectorFile, string $defaultServerMode)
{
$this->configTypeSelectorFile = $configTypeSelectorFile;
$this->fs = new Filesystem();
$this->parsed = [];
$this->defaultServerMode = $defaultServerMode;
}
public function parse(string $homeDir, bool $force = false){
if(!$force && array_key_exists($homeDir, $this->parsed)){
return;
}
$filepath = $homeDir . $this->configTypeSelectorFile;
if($this->fs->exists($filepath)){
$rawContent = file_get_contents($filepath);
if($rawContent){
$this->parsed[$homeDir] = json_decode($rawContent, true);
}
}
}
public function get(string $homeDir, string $domain): string
{
if(
$this->parsed &&
array_key_exists($homeDir, $this->parsed) &&
array_key_exists($domain, $this->parsed[$homeDir]) &&
in_array($this->parsed[$homeDir][$domain], self::AVAILABLE)
){
return $this->parsed[$homeDir][$domain];
}
return $this->defaultServerMode;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists