Skip to content

add lookup static complie php-cli #9

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
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
32 changes: 25 additions & 7 deletions discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"runtime"
"strings"

version "github.com/hashicorp/go-version"
"github.com/hashicorp/go-version"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -175,7 +193,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)
Expand Down