Skip to content

Detect PHP version from system %PATH% variable #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions discovery_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ package phpstore

import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
)

// see https://github.com/composer/windows-setup/blob/master/src/composer.iss
func (s *PHPStore) doDiscover() {
systemDir := systemDir()
userHomeDir := userHomeDir()

// %PATH%
s.addFromEnv()

// XAMPP
s.addFromDir(filepath.Join(systemDir, "xampp", "php"), nil, "XAMPP")

Expand All @@ -53,6 +58,27 @@ func (s *PHPStore) doDiscover() {
}
}

func (s *PHPStore) addFromEnv() {

// Determine the executable name based on the operating system
exeName := "php"
if runtime.GOOS == "windows" {
exeName = "php.exe"
}

// Alternative approach using exec.LookPath
phpPath, err := exec.LookPath(exeName)
if err != nil {
return
}

dir := filepath.Dir(phpPath)
if v := s.discoverPHP(dir, "php"); v != nil {
s.addVersion(v)
}

}

func systemDir() string {
cwd, err := os.Getwd()
if err != nil {
Expand Down