Todaymade\Daux\DauxHelper::getTheme PHP Method

getTheme() protected static method

protected static getTheme ( Config $params, string $current_url ) : array
$params Config
$current_url string
return array
    protected static function getTheme(Config $params, $current_url)
    {
        self::resolveVariant($params);
        $theme_folder = $params->getThemesPath() . DIRECTORY_SEPARATOR . $params['html']['theme'];
        $theme_url = $params['base_url'] . 'themes/' . $params['html']['theme'] . '/';
        $theme = [];
        if (is_file($theme_folder . DIRECTORY_SEPARATOR . 'config.json')) {
            $theme = json_decode(file_get_contents($theme_folder . DIRECTORY_SEPARATOR . 'config.json'), true);
            if (!$theme) {
                $theme = [];
            }
        }
        //Default parameters for theme
        $theme += ['name' => $params['html']['theme'], 'css' => [], 'js' => [], 'fonts' => [], 'favicon' => '<base_url>themes/daux/img/favicon.png', 'templates' => $theme_folder . DIRECTORY_SEPARATOR . 'templates', 'variants' => []];
        if (array_key_exists('theme-variant', $params['html'])) {
            $variant = $params['html']['theme-variant'];
            if (!array_key_exists($variant, $theme['variants'])) {
                throw new Exception("Variant '{$variant}' not found for theme '{$theme['name']}'");
            }
            // These will be replaced
            foreach (['templates', 'favicon'] as $element) {
                if (array_key_exists($element, $theme['variants'][$variant])) {
                    $theme[$element] = $theme['variants'][$variant][$element];
                }
            }
            // These will be merged
            foreach (['css', 'js', 'fonts'] as $element) {
                if (array_key_exists($element, $theme['variants'][$variant])) {
                    $theme[$element] = array_merge($theme[$element], $theme['variants'][$variant][$element]);
                }
            }
        }
        $substitutions = ['<local_base>' => $params['local_base'], '<base_url>' => $current_url, '<theme_url>' => $theme_url];
        // Substitute some placeholders
        $theme['templates'] = strtr($theme['templates'], $substitutions);
        $theme['favicon'] = utf8_encode(strtr($theme['favicon'], $substitutions));
        foreach (['css', 'js', 'fonts'] as $element) {
            foreach ($theme[$element] as $key => $value) {
                $theme[$element][$key] = utf8_encode(strtr($value, $substitutions));
            }
        }
        return $theme;
    }