Skip to content

Commit 0ff0e48

Browse files
authored
Merge pull request #2 from jedymatt/patch/use-regex
Patch: Remove dependency yaml and use regex to get sail services
2 parents 08b26a2 + d77b7b7 commit 0ff0e48

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

composer.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@
3838
"prefer-stable": true,
3939
"require": {
4040
"php": "^7.3|^8.0",
41-
"symfony/yaml": "^6.0",
4241
"laravel/sail": "^1.0"
4342
},
4443
"require-dev": {
4544
"laravel/pint": "^1.0"
46-
},
47-
"scripts": {
48-
"lint": "vendor/bin/pint"
4945
}
5046
}

src/Console/SailEnvCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Jedymatt\LaravelSailEnv\Console;
44

55
use Laravel\Sail\Console\InstallCommand;
6-
use Symfony\Component\Yaml\Yaml;
76

87
class SailEnvCommand extends InstallCommand
98
{
@@ -68,12 +67,14 @@ public function handle()
6867

6968
protected function servicesFromDockerCompose(): array
7069
{
71-
$dockerCompose = Yaml::parseFile($this->laravel->basePath('docker-compose.yml'));
70+
$environment = file_get_contents($this->laravel->basePath('docker-compose.yml'));
7271

73-
$sailServices = array_filter($dockerCompose['services'], function ($service) {
74-
return in_array($service, $this->services);
75-
}, ARRAY_FILTER_USE_KEY);
72+
$regex = '/'.implode('|', array_map(function ($service) {
73+
return '(?<=\s)'.$service.'(?=:)'; // Match service name followed by ':' (e.g. mysql:) and preceded by whitespace
74+
}, $this->services)).'/';
7675

77-
return array_keys($sailServices);
76+
preg_match_all($regex, $environment, $matches);
77+
78+
return array_values($matches[0]);
7879
}
7980
}

0 commit comments

Comments
 (0)