🔒 HasComposerLock
Checks whether a composer.lock file exists in the current working directory, used to determine whether the project has locked dependency versions.
When to use
composer.lock records the exact installed dependency versions. Use this when you need to determine whether a project has already run composer install and is in a "locked" state. CI pipelines often use this to decide whether to run install or update.
Signature
go
func (c *Composer) HasComposerLock() boolParameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| Single return value | bool | Returns true when composer.lock exists in the current working directory, otherwise false |
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.Fatalf("Initialization failed: %v", err)
}
if comp.HasComposerLock() {
fmt.Println("composer.lock present, dependencies locked ✅")
} else {
fmt.Println("composer.lock missing, run composer install 🔧")
}
}Advanced
- To read structured contents of the lock file, use ReadComposerLock.
- To check whether the vendor directory has been generated, combine with HasVendorDir.
- To extract the list of abandoned packages from the lock, use GetAbandonedPackagesFromLock.