From 104718e9ef8efafbdce5151a9fd89d52fbb8aee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinier=20N=C3=A1poles=20Mart=C3=ADnez?= Date: Sun, 9 Mar 2025 08:41:48 -0500 Subject: [PATCH 1/6] Detect PHP version from system %PATH% variable --- discovery_windows.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/discovery_windows.go b/discovery_windows.go index f1cbe10..bde859d 100644 --- a/discovery_windows.go +++ b/discovery_windows.go @@ -21,8 +21,10 @@ package phpstore import ( "os" + "os/exec" "path/filepath" "regexp" + "runtime" ) // see https://github.com/composer/windows-setup/blob/master/src/composer.iss @@ -30,6 +32,9 @@ func (s *PHPStore) doDiscover() { systemDir := systemDir() userHomeDir := userHomeDir() + // %PATH% + s.addFromEnv() + // XAMPP s.addFromDir(filepath.Join(systemDir, "xampp", "php"), nil, "XAMPP") @@ -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 { From c8836dfede83a744f3c652f1ec0cfebf1cadfccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinier=20N=C3=A1poles=20Mart=C3=ADnez?= Date: Mon, 10 Mar 2025 09:00:31 -0500 Subject: [PATCH 2/6] Update discovery_windows.go Co-authored-by: Tugdual Saunier --- discovery_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discovery_windows.go b/discovery_windows.go index bde859d..03ff359 100644 --- a/discovery_windows.go +++ b/discovery_windows.go @@ -58,7 +58,7 @@ func (s *PHPStore) doDiscover() { } } -func (s *PHPStore) addFromEnv() { +func (s *PHPStore) addFromPath() { // Determine the executable name based on the operating system exeName := "php" From f06cd98959975e4f6a576349eda989aa211a6fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinier=20N=C3=A1poles=20Mart=C3=ADnez?= Date: Mon, 10 Mar 2025 09:00:38 -0500 Subject: [PATCH 3/6] Update discovery_windows.go Co-authored-by: Tugdual Saunier --- discovery_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discovery_windows.go b/discovery_windows.go index 03ff359..7719a6d 100644 --- a/discovery_windows.go +++ b/discovery_windows.go @@ -33,7 +33,7 @@ func (s *PHPStore) doDiscover() { userHomeDir := userHomeDir() // %PATH% - s.addFromEnv() + s.addFromPath() // XAMPP s.addFromDir(filepath.Join(systemDir, "xampp", "php"), nil, "XAMPP") From f35e8ff3ccde6479ac79dcb0446802719e21bb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinier=20N=C3=A1poles=20Mart=C3=ADnez?= Date: Mon, 10 Mar 2025 09:00:59 -0500 Subject: [PATCH 4/6] Update discovery_windows.go Co-authored-by: Tugdual Saunier --- discovery_windows.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/discovery_windows.go b/discovery_windows.go index 7719a6d..10c3e14 100644 --- a/discovery_windows.go +++ b/discovery_windows.go @@ -60,14 +60,7 @@ func (s *PHPStore) doDiscover() { func (s *PHPStore) addFromPath() { - // 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) + phpPath, err := exec.LookPath("php.exe") if err != nil { return } From 2e6b58c76600fac3bc8444beb6885ba8e0e76429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinier=20N=C3=A1poles=20Mart=C3=ADnez?= Date: Fri, 28 Mar 2025 13:53:03 -0500 Subject: [PATCH 5/6] Fix: remove unused "runtime" import --- discovery_windows.go | 1 - 1 file changed, 1 deletion(-) diff --git a/discovery_windows.go b/discovery_windows.go index 10c3e14..db4a7bf 100644 --- a/discovery_windows.go +++ b/discovery_windows.go @@ -24,7 +24,6 @@ import ( "os/exec" "path/filepath" "regexp" - "runtime" ) // see https://github.com/composer/windows-setup/blob/master/src/composer.iss From ff873c9ddbff2eef92342bd465a122cc97d5d64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinier=20N=C3=A1poles=20Mart=C3=ADnez?= Date: Fri, 28 Mar 2025 14:02:36 -0500 Subject: [PATCH 6/6] Fix symfony-cli/phpstore#16 --- discovery_windows.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/discovery_windows.go b/discovery_windows.go index db4a7bf..8b4065f 100644 --- a/discovery_windows.go +++ b/discovery_windows.go @@ -72,11 +72,13 @@ func (s *PHPStore) addFromPath() { } func systemDir() string { - cwd, err := os.Getwd() - if err != nil { + + val, ok := os.LookupEnv("SystemDrive") + if !ok { return "C:\\" } - return filepath.VolumeName(cwd) + "\\" + + return val + string(os.PathSeparator) } func userHomeDir() string {