-
Notifications
You must be signed in to change notification settings - Fork 11
/
detect.go
46 lines (39 loc) · 1.14 KB
/
detect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package phpdist
import (
"os"
"github.com/paketo-buildpacks/packit/v2"
)
//go:generate faux --interface VersionParser --output fakes/version_parser.go
// BuildPlanMetadata is the buildpack specific data included in build plan
// requirements.
type BuildPlanMetadata struct {
Version string `toml:"version"`
VersionSource string `toml:"version-source"`
}
// Detect will return a packit.DetectFunc that will be invoked during the
// detect phase of the buildpack lifecycle.
//
// Detect always passes, and will contribute a Build Plan that provides php.
func Detect() packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
var requirements []packit.BuildPlanRequirement
version := os.Getenv("BP_PHP_VERSION")
if version != "" {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: "php",
Metadata: BuildPlanMetadata{
Version: version,
VersionSource: "BP_PHP_VERSION",
},
})
}
return packit.DetectResult{
Plan: packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: "php"},
},
Requires: requirements,
},
}, nil
}
}