Sindbad~EG File Manager

Current Path : /opt/nginxhttpd_/src/DataTransformer/
Upload File :
Current File : //opt/nginxhttpd_/src/DataTransformer/Expand.php

<?php

namespace App\DataTransformer;


class Expand implements PostDataTransformerInterface
{

    protected const IGNORED_PREFIX = ['www', 'mail', 'cpanel', 'webdisk', 'autodiscover', 'webmail', 'autoconfig',
        'whm', 'cpcalendars', 'cpcontacts', '_wildcard_'];

    /**
     * @param array $d all the data after a first wave of parsing
     * @return array
     */
    public function transform(array $d): array
    {
        $new = $d;
        // For each Vhost found
        foreach($d as $k => $r){
            if(!isset($r['serverAlias']) || count($r['serverAlias']) === 0){
                continue;
            }
            // For each alias found in a specific vhosts
            foreach($r['serverAlias'] as $alias){
                if($alias == 'default'){
                    continue;
                }

                // TODO : Tests if we really need to do something about specials subdomains
                $ignored = array_merge(self::IGNORED_PREFIX, [
                    $k,
                    str_replace('.', '-', $k),
                    $r['serverName']
                ]);

                // Ignore the useless aliases
                foreach ($ignored as $i) {
                    if (strpos($alias, $i . '.') === 0) {
                        continue 2;
                    }
                }

                // For non useless vhosts, like some real alias, duplicate the conf with a new Key
                $new[$alias] = $r;
            }
        }

        return $new;
    }

}

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