Skip to content

🔒 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() bool

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
Single return valueboolReturns 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

Released under the MIT License