Sindbad~EG File Manager
<?php
namespace App\Service\Lsws;
use Exception;
use Symfony\Component\Filesystem\Filesystem;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
class LswsConfigManager
{
/**
* @var string
*/
protected $lswsHttpdConf;
/**
* @var Filesystem
*/
protected $fs;
/**
* @var Environment
*/
private $twig;
public function __construct(string $lswsHttpdConf, Environment $twig)
{
$this->lswsHttpdConf = $lswsHttpdConf;
$this->fs = new Filesystem();
$this->twig = $twig;
}
/**
* @throws Exception
*/
public function initialize(bool $force = false): void
{
try {
$config = $this->twig->render('lswsconf/lswsconf.conf.twig');
} catch (LoaderError|RuntimeError|SyntaxError $e) {
throw new Exception("Error when loading lsws config template");
}
if($this->fs->exists($this->lswsHttpdConf)){
if(!$force){
throw new Exception("Config is already set. To erase it, add force param.");
}
}else{
$this->fs->touch($this->lswsHttpdConf);
}
$this->fs->chmod($this->lswsHttpdConf, 0750);
$this->fs->chown($this->lswsHttpdConf, 'lsadm');
$this->fs->chgrp($this->lswsHttpdConf, 'nobody');
$this->fs->dumpFile($this->lswsHttpdConf, $config);
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists