Skip to content

🖥️ 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 ​

ParameterTypeDescription
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 contains Name, Version, Available, and Required fields
  • error: Returned when executing composer check-platform --format=json or 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 ​

Released under the MIT License