Skip to content

Commit 19d57c1

Browse files
authored
Add support for PHP version selection based on config.platform.php in composer.json (#4)
1 parent b99381b commit 19d57c1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

store.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ func (s *PHPStore) BestVersionForDir(dir string) (*Version, string, string, erro
8888
return s.bestVersion(string(version), fmt.Sprintf(".php-version from current dir: %s", filepath.Join(foundDir, ".php-version")))
8989
}
9090

91+
// composer.json for the currently executed PHP script and up
92+
if version, foundDir := s.versionForDir(dir, "composer.json"); version != nil {
93+
var composerJson struct {
94+
Config struct {
95+
Platform struct {
96+
PHP string `json:"php"`
97+
} `json:"platform"`
98+
} `json:"config"`
99+
}
100+
if err := json.Unmarshal(version, &composerJson); err == nil && composerJson.Config.Platform.PHP != "" {
101+
return s.bestVersion(composerJson.Config.Platform.PHP, fmt.Sprintf("composer.json from current dir: %s", filepath.Join(foundDir, "composer.json")))
102+
}
103+
}
104+
91105
// .php-version for the current working directory and up
92106
wd, err := os.Getwd()
93107
if err == nil {

0 commit comments

Comments
 (0)