Skip to content

Commit 25e2b81

Browse files
committed
fix: Convert environment variables to one format in shared.php
1 parent 59383d3 commit 25e2b81

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

bootstrap/helpers/shared.php

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
32063206
}
32073207
}
32083208
// convert environment variables to one format
3209+
ray($environment);
32093210
$environment = convertComposeEnvironmentToArray($environment);
32103211

32113212
// Add Coolify defined environments
@@ -3639,37 +3640,22 @@ function add_coolify_default_environment_variables(StandaloneRedis|StandalonePos
36393640
$where_to_add->push("COOLIFY_PROJECT_NAME={$resource->project()->name}");
36403641
}
36413642
}
3642-
ray($where_to_add);
36433643
}
36443644

36453645
function convertComposeEnvironmentToArray($environment)
36463646
{
36473647
$convertedServiceVariables = collect([]);
3648-
foreach ($environment as $variableName => $variableValue) {
3649-
if (is_array($variableValue)) {
3650-
$key = str(collect($variableValue)->keys()->first());
3651-
$value = str(collect($variableValue)->values()->first());
3652-
} elseif (is_string($variableValue)) {
3653-
if (str($variableValue)->contains('=')) {
3654-
$key = str($variableValue)->before('=');
3655-
$value = str($variableValue)->after('=');
3656-
} else {
3657-
if (is_numeric($variableName)) {
3658-
$key = str($variableValue);
3659-
$value = null;
3660-
} else {
3661-
$key = str($variableName);
3662-
if ($variableValue) {
3663-
$value = str($variableValue);
3664-
} else {
3665-
$value = null;
3666-
}
3667-
}
3648+
if (isAssociativeArray($environment)) {
3649+
$convertedServiceVariables = $environment;
3650+
} else {
3651+
foreach ($environment as $value) {
3652+
$parts = explode('=', $value, 2);
3653+
$key = $parts[0];
3654+
$realValue = $parts[1] ?? '';
3655+
if ($key) {
3656+
$convertedServiceVariables->put($key, $realValue);
36683657
}
36693658
}
3670-
if ($key) {
3671-
$convertedServiceVariables->put($key->value(), $value?->value() ?? null);
3672-
}
36733659
}
36743660

36753661
return $convertedServiceVariables;

0 commit comments

Comments
 (0)