Skip to content

🖥️ CheckPlatformReqs — Check platform requirements

🔍 CheckPlatformReqs checks whether the current runtime environment satisfies the PHP extensions and platform requirements declared in composer.json, equivalent to running composer check-platform-reqs, commonly used for pre-deployment environment validation.

📋 Signature

go
func (c *Composer) CheckPlatformReqs() (string, error)

📥 Parameters

ParameterTypeDescription
NoneThis method takes no parameters

📤 Return value

Return valueTypeDescription
First return valuestringText output of the platform requirements check result
Second return valueerrorReturned when an error occurs during execution; nil on success

📝 Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.NewComposer()
	if err != nil {
		log.Fatalf("failed to create Composer instance: %v", err)
	}

	output, err := comp.CheckPlatformReqs()
	if err != nil {
		log.Fatalf("failed to check platform requirements: %v", err)
	}
	fmt.Println("Platform requirements check result:")
	fmt.Println(output)
}

🚀 Advanced

  • 📋 To get results in json or text format for programmatic parsing, use CheckPlatformReqsWithFormat(format).
  • 🧪 Calling this method in a deployment script can surface missing PHP extensions (e.g. ext-mbstring, ext-pdo) before installing dependencies.
  • ⚠️ When platform requirements are not satisfied, Composer exits with a non-zero exit code and Run returns an error; use this to abort the deployment flow.
  • 🔗 Use in combination with Validate(): first use Validate() to check the composer.json format, then use this method to validate the runtime environment.

Released under the MIT License