8000 add lookup static complie php-cli by jingjingxyk · Pull Request #9 · symfony-cli/phpstore · GitHub
[go: up one dir, main page]

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 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
Prev Previous commit
add checkout static php version
  • Loading branch information
jingjingxyk committed Apr 11, 2023
commit d6883324c60cbb766fda2d00d9ead743f8df4c2c
30 changes: 24 additions & 6 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 Down
0