📦 IsProject
Checks whether the current working directory is a Composer project (i.e. whether a composer.json file exists); it does not execute any Composer commands.
When to use
Use this before performing operations such as install or dependency analysis to first determine whether the current directory is actually a PHP/Composer project, avoiding mistakes on non-project directories. It reads the filesystem directly and is extremely fast.
Signature
go
func (c *Composer) IsProject() boolParameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| Single return value | bool | Returns true when composer.json 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.IsProject() {
fmt.Println("The current directory is a Composer project ✅")
} else {
fmt.Println("The current directory is not a Composer project ❌")
}
}Advanced
- To check whether a specific directory is a Composer project, use IsProjectIn.
- To confirm whether a project has already run
composer install, combine HasComposerLock and HasVendorDir. - To read the complete
composer.jsoncontent, use ReadComposerJson.