66
77use WebProject \DockerApi \Library \Generated \Model \ContainerInspectResponse ;
88use WebProject \DockerApiClient \Dto \DockerContainerDto ;
9- use function array_map ;
109use function array_unique ;
1110use function explode ;
11+ use function is_string ;
12+ use function str_contains ;
1213
1314final readonly class ContainerResponseToContainerDtoUtil
1415{
@@ -27,12 +28,21 @@ public function __invoke(
2728 $ ipAddresses [] = $ network ->getIPAddress ();
2829 }
2930
31+ $ envVariables = [];
32+ foreach ($ containerInspect ->getConfig ()->getEnv () ?? [] as $ envVar ) {
33+ if (!is_string ($ envVar ) || !str_contains ($ envVar , '= ' )) {
34+ continue ;
35+ }
36+ [$ name , $ value ] = explode ('= ' , $ envVar );
37+ $ envVariables [$ name ] = $ value ;
38+ }
39+
3040 return new DockerContainerDto (
3141 id: $ containerInspect ->getId (),
3242 name: $ containerInspect ->getName (),
3343 image: $ containerInspect ->getImage (),
3444 running: $ containerInspect ->getState ()?->getRunning() ?? false ,
35- envVariables: array_map ( static fn ( string $ envVar ) => explode ( ' = ' , $ envVar ), $ containerInspect -> getConfig ()-> getEnv () ?? []) ,
45+ envVariables: $ envVariables ,
3646 ipAddresses: $ ipAddresses ,
3747 networks: $ networks ,
3848 ports: (array ) ($ containerInspect ->getNetworkSettings ()->getPorts () ?? []),
0 commit comments