Olivier Massot vor 9 Monaten
Ursprung
Commit
6fd31c5b2f
1 geänderte Dateien mit 11 neuen und 6 gelöschten Zeilen
  1. 11 6
      src/Service/Typo3/BindFileService.php

+ 11 - 6
src/Service/Typo3/BindFileService.php

@@ -2,15 +2,19 @@
 
 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
  */
-class BindFileService
+readonly class BindFileService
 {
     public function __construct(
-        readonly private string $bindfileBufferFile,
+        private string $bindfileBufferFile,
     ) {
     }
 
@@ -18,12 +22,13 @@ class BindFileService
      * 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
+     * @param string $subdomain
+     * @throws FileNotFoundException
+     * @throws IOException
      */
     public function registerSubdomain(string $subdomain): void
     {
-        $fsd = fopen($this->bindfileBufferFile, 'ab+');
-        fwrite($fsd, $subdomain);
-        fwrite($fsd, "\n");
-        fclose($fsd);
+        $bindFile = new Path($this->bindfileBufferFile);
+        $bindFile->putContent($subdomain . '\n', true);
     }
 }