Sindbad~EG File Manager

Current Path : /proc/self/root/proc/self/root/opt/nginxhttpd_/src/Parser/
Upload File :
Current File : //proc/self/root/proc/self/root/opt/nginxhttpd_/src/Parser/AbstractHttpdParser.php

<?php

namespace App\Parser;

use App\DataTransformer\DataTransformerInterface;
use Symfony\Component\Filesystem\Filesystem;

abstract class AbstractHttpdParser
{
    /**
     * @var Filesystem
     */
    protected $fs;
    /**
     * @var DataTransformerInterface[]
     */
    protected array $transformer = [];
    protected array $result = [];

    public function __construct(
        protected int $httpsPort,
        protected int $httpPort
    ){
        $this->fs = new Filesystem();
    }

    /**
     * Parse the apache httpd.conf and return a boolean
     * @param string $filepath
     * @param string|null $domainToUpdate If provided, just update one domain
     * @return bool
     */
    public abstract function parse(string $filepath, ?string $domainToUpdate = null ) : bool;

    /**
     * Set the data transformer that can be use to modify/enrich the data
     * @param DataTransformerInterface[] $transformer
     */
    public function setDataTransformer(array $transformer){
        foreach ($transformer as $t){
            if(class_implements($t, DataTransformerInterface::class)){
                $this->transformer[] = $t;
            }
        }
        return $this;
    }

    /**
     * Return the data parsed
     * @return array|bool
     */
    public function getData(){
        if(is_array($this->result) && count($this->result) > 0){
            return $this->result;
        }
        return false;
    }

    /**
     * Transform / enrich the data
     */
    protected function transform(){
        if(empty($this->transformer) || count($this->transformer) === 0) {
            return;
        }

        // Foreach on the transformer first, as the Key can change, so $this->result can change too
        foreach($this->transformer as $t) {
            if (!is_subclass_of($t, DataTransformerInterface::class)) {
                continue;
            }
            foreach ($this->result as $k => $v) {
                list($newvar, $newkey) = $t->transform($v, $k);
                if ($newkey != $k && !is_null($newkey)) {
                    // The key can change. Used for addon domain because of the shit management of cPanel that create a
                    // fucking subdomain and put in in the main serverName instead of the real domain.
                    // Why ? Because Fuck You, that's why. Thanks cPanel.
                    unset($this->result[$k]);
                    $this->result[$newkey] = $newvar;
                } else {
                    $this->result[$k] = $newvar;
                }
            }
        }
    }

    protected function getContent($filepath){
        if(!$this->fs->exists($filepath)){
            return false;
        }
        return file_get_contents($filepath);
    }
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists