✅ IsPlatformAvailable
Checks whether the specified platform requirement (such as php or ext-mbstring) is available in the current environment.
When to use
Use this in deployment scripts or runtime self-checks when you need to quickly determine whether a PHP extension or PHP version constraint is satisfied.
Signature
go
func (c *Composer) IsPlatformAvailable(platform string, version string) (bool, error)Parameters
| Parameter | Type | Description |
|---|---|---|
platform | string | Platform name, e.g. php or ext-mbstring |
version | string | Version constraint, e.g. >=7.4; may be an empty string to indicate no version constraint |
Return value
bool:trueif the platform requirement is satisfied, otherwisefalseerror: Returns an error when command execution or parsing fails during the check
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)
}
// Check PHP version
ok, err := comp.IsPlatformAvailable("php", ">=7.4")
if err != nil {
log.Fatal(err)
}
fmt.Println("PHP>=7.4 satisfied:", ok)
// Check whether the extension is installed
ok, err = comp.IsPlatformAvailable("ext-mbstring", "")
if err != nil {
log.Fatal(err)
}
fmt.Println("mbstring extension installed:", ok)
}Advanced
- This method first calls CheckPlatform to look up the requirement; if the platform is not listed in
composer.json, it directly runscomposer check-platform <name>:<version>to probe - It decides availability based on whether the output contains
is not available - If you only need to list all extensions, use GetExtensions