@@ -3573,6 +3573,23 @@ function generate_fluentd_configuration(): array
3573
3573
];
3574
3574
}
3575
3575
3576
+ function isAssociativeArray ($ array )
3577
+ {
3578
+ if ($ array instanceof Collection) {
3579
+ $ array = $ array ->toArray ();
3580
+ }
3581
+
3582
+ if (! is_array ($ array )) {
3583
+ throw new \InvalidArgumentException ('Input must be an array or a Collection. ' );
3584
+ }
3585
+
3586
+ if ($ array === []) {
3587
+ return false ;
3588
+ }
3589
+
3590
+ return array_keys ($ array ) !== range (0 , count ($ array ) - 1 );
3591
+ }
3592
+
3576
3593
/**
3577
3594
* This method adds the default environment variables to the resource.
3578
3595
* - COOLIFY_APP_NAME
@@ -3584,42 +3601,45 @@ function generate_fluentd_configuration(): array
3584
3601
*/
3585
3602
function add_coolify_default_environment_variables (StandaloneRedis |StandalonePostgresql |StandaloneMongodb |StandaloneMysql |StandaloneMariadb |StandaloneKeydb |StandaloneDragonfly |StandaloneClickhouse |Application |Service $ resource , Collection &$ where_to_add , ?Collection $ where_to_check = null )
3586
3603
{
3604
+ if ($ resource instanceof Service) {
3605
+ $ ip = $ resource ->server ->ip ;
3606
+ } else {
3607
+ $ ip = $ resource ->destination ->server ->ip ;
3608
+ }
3609
+ if (isAssociativeArray ($ where_to_add )) {
3610
+ $ isAssociativeArray = true ;
3611
+ } else {
3612
+ $ isAssociativeArray = false ;
3613
+ }
3587
3614
if ($ where_to_check != null && $ where_to_check ->where ('key ' , 'COOLIFY_APP_NAME ' )->isEmpty ()) {
3588
- if ($ resource instanceof Application && $ resource ->build_pack === 'dockercompose ' ) {
3589
- $ where_to_add ->put ('COOLIFY_APP_NAME ' , $ resource ->name );
3590
- } elseif ($ resource instanceof Service) {
3615
+ if ($ isAssociativeArray ) {
3591
3616
$ where_to_add ->put ('COOLIFY_APP_NAME ' , $ resource ->name );
3592
3617
} else {
3593
3618
$ where_to_add ->push ("COOLIFY_APP_NAME= {$ resource ->name }" );
3594
3619
}
3595
3620
}
3596
3621
if ($ where_to_check != null && $ where_to_check ->where ('key ' , 'COOLIFY_SERVER_IP ' )->isEmpty ()) {
3597
- if ($ resource instanceof Application && $ resource ->build_pack === 'dockercompose ' ) {
3598
- $ where_to_add ->put ('COOLIFY_SERVER_IP ' , $ resource ->destination ->server ->ip );
3599
- } elseif ($ resource instanceof Service) {
3600
- $ where_to_add ->put ('COOLIFY_SERVER_IP ' , $ resource ->server ->ip );
3622
+ if ($ isAssociativeArray ) {
3623
+ $ where_to_add ->put ('COOLIFY_SERVER_IP ' , $ ip );
3601
3624
} else {
3602
- $ where_to_add ->push ("COOLIFY_SERVER_IP= {$ resource -> destination -> server -> ip }" );
3625
+ $ where_to_add ->push ("COOLIFY_SERVER_IP= {$ ip }" );
3603
3626
}
3604
3627
}
3605
3628
if ($ where_to_check != null && $ where_to_check ->where ('key ' , 'COOLIFY_ENVIRONMENT_NAME ' )->isEmpty ()) {
3606
- if ($ resource instanceof Application && $ resource ->build_pack === 'dockercompose ' ) {
3607
- $ where_to_add ->put ('COOLIFY_ENVIRONMENT_NAME ' , $ resource ->environment ->name );
3608
- } elseif ($ resource instanceof Service) {
3629
+ if ($ isAssociativeArray ) {
3609
3630
$ where_to_add ->put ('COOLIFY_ENVIRONMENT_NAME ' , $ resource ->environment ->name );
3610
3631
} else {
3611
3632
$ where_to_add ->push ("COOLIFY_ENVIRONMENT_NAME= {$ resource ->environment ->name }" );
3612
3633
}
3613
3634
}
3614
3635
if ($ where_to_check != null && $ where_to_check ->where ('key ' , 'COOLIFY_PROJECT_NAME ' )->isEmpty ()) {
3615
- if ($ resource instanceof Application && $ resource ->build_pack === 'dockercompose ' ) {
3616
- $ where_to_add ->put ('COOLIFY_PROJECT_NAME ' , $ resource ->project ()->name );
3617
- } elseif ($ resource instanceof Service) {
3636
+ if ($ isAssociativeArray ) {
3618
3637
$ where_to_add ->put ('COOLIFY_PROJECT_NAME ' , $ resource ->project ()->name );
3619
3638
} else {
3620
3639
$ where_to_add ->push ("COOLIFY_PROJECT_NAME= {$ resource ->project ()->name }" );
3621
3640
}
3622
3641
}
3642
+ ray ($ where_to_add );
3623
3643
}
3624
3644
3625
3645
function convertComposeEnvironmentToArray ($ environment )
0 commit comments