| 70 | } |
| 71 | |
| 72 | func (d *PHPDetector) phpExtensions(ctx context.Context) ([]string, error) { |
| 73 | resolved, err := searcher.Client().ResolveV2(ctx, "php", d.phpVersion(ctx)) |
| 74 | if err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | |
| 78 | // extract major-minor from resolved.Version |
| 79 | re := regexp.MustCompile(`^(\d+)\.(\d+)`) |
| 80 | matches := re.FindStringSubmatch(resolved.Version) |
| 81 | if len(matches) < 3 { |
| 82 | return nil, fmt.Errorf("could not parse PHP version: %s", resolved.Version) |
| 83 | } |
| 84 | majorMinor := matches[1] + matches[2] |
| 85 | |
| 86 | extensions := []string{} |
| 87 | for key := range d.composerJSON.Require { |
| 88 | if strings.HasPrefix(key, "ext-") { |
| 89 | // The way nix versions php extensions is inconsistent. Sometimes the version is the PHP |
| 90 | // version, sometimes it's the extension version. We just use @latest everywhere which in |
| 91 | // practice will just use the version of the extension that exists in the same nixpkgs as |
| 92 | // the php version. |
| 93 | extensions = append( |
| 94 | extensions, |
| 95 | fmt.Sprintf("php%sExtensions.%s@latest", majorMinor, strings.TrimPrefix(key, "ext-")), |
| 96 | ) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return extensions, nil |
| 101 | } |
| 102 | |
| 103 | func loadComposerJSON(root string) (*composerJSON, error) { |
| 104 | composerPath := filepath.Join(root, "composer.json") |