Skip to content
Snippets Groups Projects
TikiWIkiConfig.php 1.03 KiB
Newer Older
<?php

namespace Ingress\Services\tikiwiki;

class TikiWIkiConfig
{
    private const CONFIG_PATH='./config/tikiwiki.json';

    public static function getTrackers(string $domain) {

        if (!file_exists(TikiWIkiConfig::CONFIG_PATH)) {
            die("File not found: " . TikiWIkiConfig::CONFIG_PATH);
        }

        // Read the contents of the JSON file
        $jsonContent = file_get_contents(TikiWIkiConfig::CONFIG_PATH);

        if ($jsonContent === false) {
            die("Error reading file: " . TikiWIkiConfig::CONFIG_PATH);
        }

        // Decode the JSON data into a PHP array
        $dataArray = json_decode($jsonContent, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            die("Error decoding JSON: " . json_last_error_msg());
        }

        if (! array_key_exists('domains', $dataArray) || ! array_key_exists($domain, $dataArray['domains'])) {
            die("Missing domain configuration: " . json_last_error_msg());
        }

        return $dataArray['domains'][$domain]['trackers'];
    }

}