Skip to content
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