<?php

declare(strict_types=1);

namespace App\Service\Typo3;

use Path\Exception\FileNotFoundException;
use Path\Exception\IOException;
use Path\Path;

/**
 * Opérations sur le fichier Bind, qui gère entre autres l'adressage DNS lié aux sous-domaines.
 *
 * @codeCoverageIgnore
 */
readonly class BindFileService
{
    public function __construct(
        private string $bindfileBufferFile,
    ) {
    }

    /**
     * Append the subdomain to the buffer file.
     *
     * A cron consumes this file each 5 minutes to complete the bind file /etc/bind/zones/opentalent.fr.db
     *
     * @throws FileNotFoundException
     * @throws IOException
     */
    public function registerSubdomain(string $subdomain): void
    {
        $bindFile = new Path($this->bindfileBufferFile);
        $bindFile->putContent($subdomain."\n", true);
    }
}
