Skip to content

🔒 CheckPlatformWithLock

Checks whether the current system satisfies the platform requirements locked in composer.lock, returning a structured list of platform information.

When to use

In production deployment, the composer.lock is usually the source of truth; you need to confirm that the runtime environment meets the exact PHP version and extension requirements recorded in the lock file.

Signature

go
func (c *Composer) CheckPlatformWithLock() ([]PlatformInfo, error)

Parameters

ParameterTypeDescription
NoneThis method takes no parameters; it reads the current project's composer.lock directly

Return value

  • []PlatformInfo: Slice of platform requirement info parsed from composer.lock
  • error: Returned when executing composer check-platform --lock --format=json or parsing fails

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.CheckPlatformWithLock()
    if err != nil {
        log.Fatalf("failed to check lock file platform requirements: %v", err)
    }

    for _, p := range platforms {
        if !p.Available {
            fmt.Printf("Warning: %s %s requirement not satisfied\n", p.Name, p.Required)
        }
    }
}

Advanced

  • This method runs composer check-platform --lock --format=json internally and only reads the Lock field
  • The non-lock version is CheckPlatform
  • To validate lock file sync in one go, use it together with CheckStructured

Released under the MIT License