Start project PHP Back.

50% routes.
This commit is contained in:
2026-03-20 11:40:11 +01:00
parent fedbf51c91
commit c36b95a15f
13 changed files with 555 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Helpers;
use App\Exceptions\ConfigFailedLoadingException;
/**
* Classe outillage qui permet de charger les fichiers de configuration.
*/
class ConfigFactory {
/**
* Chemin relatif à partir de APP_ROOT du dossier contenant les fichiers de configuration.
*
* @see APP_ROOT
*/
const string CONFIG_RELATIVE_FOLDER = "config/";
/**
* Permet de charger un fichier de configuration.
*
* @param string $fileName Le nom du fichier de configuration, avec ou sans l'extension .php.
* @return array
*
* @throws ConfigFailedLoadingException
*/
public static function loadConfigFile( string $fileName ): array {
if( !str_ends_with( $fileName, ".php" ) ) {
$fileName .= ".php";
}
$filePath = APP_ROOT . self::CONFIG_RELATIVE_FOLDER . $fileName;
if( !file_exists( $filePath ) ){
throw new ConfigFailedLoadingException( "Config file '$fileName' does not exist" );
}
$configArray = require $filePath;
return $configArray;
}
}