Skip to content

Commit 090108d

Browse files
committed
fix: améliorer la fonction d'environnement pour une meilleure gestion des environnements
1 parent cbfda83 commit 090108d

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

src/Controllers/ApplicationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function view(string $view, array $data = [], array $options = []): Vi
5757
$cachedPaths[static::class] = is_dir($fullpath) ? $fullpath : $dirname . DS;
5858
}
5959

60-
$view = $cachedPaths[static::class] . $view;
60+
$view = str_replace([VIEW_PATH, DS], ['', '/'], $cachedPaths[static::class] . $view);
6161
}
6262

6363
/** @var View */

src/Helpers/common.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -473,18 +473,23 @@ function method_field(string $method): string
473473

474474
if (! function_exists('environment')) {
475475
/**
476-
* Renvoi l'environnement d'execution actuel ou determine si on est dans un environnement specifie
476+
* Récupère ou vérifie l'environnement d'exécution actuel
477477
*
478-
* @return bool|string
478+
* Renvoi l'environnement d'execution actuel ou determine si on est dans un environnement specifique
479+
*
480+
* L'environnement est défini dans config/app.php via 'environment'
481+
* Les alias sont automatiquement résolus (ex: 'prod' -> 'production')
482+
*
483+
* @param array|string|null $env Environnement(s) à vérifier (optionnel)
484+
*
485+
* @return bool|string L'environnement actuel ou le résultat de la vérification
479486
*/
480487
function environment(array|string|null $env = null)
481488
{
482-
$current = env('ENVIRONMENT');
483-
if (empty($current) || $current === 'auto') {
484-
$current = config('app.environment');
485-
}
489+
/** @var string */
490+
$current = config('app.environment');
486491

487-
if (in_array($env, ['', '0', [], null], true)) {
492+
if ($env === null) {
488493
return $current;
489494
}
490495

@@ -497,13 +502,7 @@ function environment(array|string|null $env = null)
497502
'staging' => 'testing',
498503
];
499504

500-
$current = $envMap[$current] ?? $current;
501-
502-
if (is_string($env)) {
503-
$env = [$env];
504-
}
505-
506-
$env = array_map(static fn ($k) => $envMap[$k] ?? $k, $env);
505+
$env = array_map(static fn ($k) => $envMap[$k] ?? $k, (array) $env);
507506

508507
return in_array($current, $env, true);
509508
}

0 commit comments

Comments
 (0)