renommer fichier de config pman

This commit is contained in:
Jephté Clain 2025-03-23 06:58:56 +04:00
parent c3357de203
commit 0e9c4e971d
5 changed files with 24 additions and 6 deletions

View File

@ -3,7 +3,7 @@
require __DIR__ . "/../vendor/autoload.php";
use nulib\tools\pman\ComposerFile;
use nulib\tools\pman\PmanYamlConfigFile;
use nulib\tools\pman\ComposerPmanFile;
use nulib\ValueException;
$composer = new ComposerFile();

View File

@ -3,11 +3,11 @@
require __DIR__ . "/../vendor/autoload.php";
use nulib\tools\pman\ComposerFile;
use nulib\tools\pman\PmanYamlConfigFile;
use nulib\tools\pman\ComposerPmanFile;
use nulib\ValueException;
$composer = new ComposerFile();
$config = new PmanYamlConfigFile();
$config = new ComposerPmanFile();
if ($argc <= 1) {
throw new ValueException("Il faut spécifier le profil à sélectionner");

View File

@ -77,7 +77,7 @@ class ComposerFile {
"nulib/php" => "nulib",
];
function selectProfile(string $profile, PmanYamlConfigFile $config): void {
function selectProfile(string $profile, ComposerPmanFile $config): void {
$config = $config->getProfileConfig($profile);
// corriger les liens
$deps = cl::merge(array_keys($config["require"]), array_keys($config["require-dev"]));

View File

@ -6,9 +6,27 @@ use nulib\ext\yaml;
use nulib\os\path;
use nulib\ValueException;
class PmanYamlConfigFile {
class ComposerPmanFile {
const NAMES = [".composer.pman", ".pman"];
const EXTS = [".yml", ".yaml"];
function __construct(string $configFile=".", bool $ensureExists=true) {
if (is_dir($configFile)) $configFile = path::join($configFile, '.pman.yml');
if (is_dir($configFile)) {
$found = false;
foreach (self::NAMES as $name) {
foreach (self::EXTS as $ext) {
$file = path::join($configFile, "$name$ext");
if (file_exists($file)) {
$configFile = $file;
$found = true;
break;
}
}
}
if (!$found) {
$configFile = path::join($configFile, self::NAMES[0].self::EXTS[0]);
}
}
if ($ensureExists && !file_exists($configFile)) {
$message = path::ppath($configFile).": fichier introuvable";
throw new ValueException($message);