🔒 ValidateComposerLock
Verifies that the composer.lock file exists and is in sync with composer.json. Equivalent to running composer validate --check-lock.
When to use
Use this when you need to ensure the lock file is not missing and has not fallen out of sync due to composer.json changes. Commonly used in CI to prevent cases where a developer committed composer.json changes but forgot to update the lock.
Signature
go
func (c *Composer) ValidateComposerLock() (string, error)Parameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Raw output of the validation command |
| Second return value | error | Returned when the lock is missing or out of sync |
Example
go
package main
import (
"fmt"
"log"
"strings"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatalf("init failed: %v", err)
}
output, err := comp.ValidateComposerLock()
if err != nil {
switch {
case strings.Contains(output, "not found"):
fmt.Println("missing composer.lock file")
case strings.Contains(output, "not up to date"):
fmt.Println("composer.lock is out of date, please run composer update")
default:
log.Fatalf("validation failed: %v", err)
}
return
}
fmt.Println("composer.lock is valid")
}Advanced
- For full
composer.jsonvalidation, use ValidateStrict or ValidateSchema. - For structured results, use ValidateStructured.
- To check whether platform requirements in the lock are satisfied, use
CheckPlatformReqsLock().