🖥️ CheckPlatform
Checks whether the current system satisfies the platform requirements defined in composer.json (PHP version, extensions, etc.), returning a structured list of platform information.
When to use
Use when you need to determine in code whether the deployment environment meets the project's PHP version or extension requirements, e.g. CI pipeline pre-checks or container startup self-checks.
Signature
go
func (c *Composer) CheckPlatform() ([]PlatformInfo, error)Parameters
| Parameter | Type | Description |
|---|---|---|
| None | — | This method takes no parameters; it reads the current project's composer.json directly |
Return value
[]PlatformInfo: Slice of platform requirement info; each element containsName,Version,Available, andRequiredfieldserror: Returned when executingcomposer check-platform --format=jsonor parsing fails
go
type PlatformInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Available bool `json:"available"`
Required string `json:"required,omitempty"`
}Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatal(err)
}
platforms, err := comp.CheckPlatform()
if err != nil {
log.Fatalf("failed to check platform requirements: %v", err)
}
for _, p := range platforms {
status := "not satisfied"
if p.Available {
status = "satisfied"
}
fmt.Printf("%s %s: %s\n", p.Name, p.Version, status)
}
}Advanced
- To check
composer.lockinstead ofcomposer.json, use CheckPlatformWithLock - To only determine whether a single platform is available, use IsPlatformAvailable
- For structured results with status markers (
ok/missing/mismatch), use CheckPlatformReqsStructured