File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 44
55use Illuminate \Console \Command ;
66use Laravel \Sail \Console \Concerns \InteractsWithDockerComposeServices ;
7+ use Symfony \Component \Yaml \Yaml ;
78
89class SailEnvCommand extends Command
910{
@@ -59,15 +60,14 @@ public function handle()
5960
6061 protected function getServicesFromCompose (): array
6162 {
62- $ dockerComposeContent = file_get_contents ($ this ->laravel ->basePath ('docker-compose.yml ' ));
63-
64- $ regex = '/ ' .implode ('| ' , array_map (function ($ service ) {
65- return '(?<=[^\S]\s) ' .$ service .'(?=:) ' ; // Match service name followed by ':' (e.g. mysql:) and preceded only by whitespace
66- }, $ this ->services )).'/ ' ;
67-
68- preg_match_all ($ regex , $ dockerComposeContent , $ matches );
69-
70- return array_values ($ matches [0 ]);
63+ $ compose = Yaml::parseFile ($ this ->laravel ->basePath ('docker-compose.yml ' ));
64+
65+ return collect ($ compose ['services ' ])
66+ ->filter (function ($ service , $ key ) {
67+ return in_array ($ key , $ this ->services );
68+ })
69+ ->keys ()
70+ ->toArray ();
7171 }
7272
7373 protected function createEnvFile (): void
You can’t perform that action at this time.
0 commit comments