From d2d3d1cf523cf9673ee94961738f0b571b886792 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 11 Apr 2023 17:09:52 +0800 Subject: [PATCH 1/2] discoverPHPViaPHP add Swoole --- discovery.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discovery.go b/discovery.go index ea305fa..1b3c263 100644 --- a/discovery.go +++ b/discovery.go @@ -175,7 +175,7 @@ func (s *PHPStore) discoverPHPViaPHP(dir, binName string) *Version { s.log(` Unable to run "%s --version: %s"`, php, err) return nil } - r := regexp.MustCompile("PHP (\\d+\\.\\d+\\.\\d+)") + r := regexp.MustCompile("(?:PHP|Swoole) (\\d+\\.\\d+\\.\\d+)") data := r.FindSubmatch(buf.Bytes()) if data == nil { s.log(" %s is not a PHP binary", php) From d6883324c60cbb766fda2d00d9ead743f8df4c2c Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 11 Apr 2023 22:31:09 +0800 Subject: [PATCH 2/2] add checkout static php version --- discovery.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/discovery.go b/discovery.go index 1b3c263..ea45b74 100644 --- a/discovery.go +++ b/discovery.go @@ -30,7 +30,7 @@ import ( "runtime" "strings" - version "github.com/hashicorp/go-version" + "github.com/hashicorp/go-version" "github.com/pkg/errors" ) @@ -140,6 +140,12 @@ func (s *PHPStore) discoverPHP(dir, binName string) *Version { return s.discoverPHPViaPHP(dir, binName) } + phpBin := filepath.Join(dir, "php") + _, phpBinErr := os.Lstat(phpBin) + if phpBinErr != nil { + return s.discoverPHPViaPHP(dir, binName) + } + phpConfigPath := filepath.Join(dir, "bin", strings.Replace(binName, "php", "php-config", 1)) fi, err := os.Lstat(phpConfigPath) if err != nil { @@ -157,14 +163,26 @@ func (s *PHPStore) discoverPHP(dir, binName string) *Version { } func (s *PHPStore) discoverPHPViaPHP(dir, binName string) *Version { - php := filepath.Join(dir, "bin", binName) + var php string if runtime.GOOS == "windows" { binName += ".exe" php = filepath.Join(dir, binName) - } - - if _, err := os.Stat(php); err != nil { - return nil + } else { + var phpBinIsExist = 0 + var phpBin = "" + phpBin = filepath.Join(dir, binName) + if _, err := os.Stat(phpBin); err == nil { + phpBinIsExist += 1 + php = phpBin + } + phpBin = filepath.Join(dir, "bin", binName) + if _, err := os.Stat(phpBin); err == nil { + phpBinIsExist += 1 + php = phpBin + } + if phpBinIsExist < 1 { + return nil + } } var buf bytes.Buffer