Documentation
¶
Overview ¶
Package composer implements Composer build tool support for PHP projects within omnibump.
It handles parsing composer.lock files, performing dependency updates via the composer CLI, and analyzing project dependencies.
Parsing ¶
Use ParseLock to parse a composer.lock file into a list of LockPackage values representing all installed packages (both regular and dev).
Updating ¶
The Composer type implements the PHP BuildTool interface, providing detection, update, and validation operations for Composer-based projects. Updates are performed by modifying composer.json constraints and optionally running composer update.
Analysis ¶
The Analyzer type implements the analyzer.Analyzer interface, providing dependency analysis and update strategy recommendations for Composer projects. All Composer updates use direct dependency updates (no property indirection).
Index ¶
- Variables
- func DoUpdate(ctx context.Context, packages map[string]*Package, ...) error
- func RunRequire(ctx context.Context, name, version, composerRoot string, extraArgs ...string) (string, error)
- func RunRequireDev(ctx context.Context, name, version, composerRoot string, extraArgs ...string) (string, error)
- func RunUpdate(ctx context.Context, composerRoot string, extraArgs ...string) (string, error)
- type Analyzer
- func (ca *Analyzer) Analyze(ctx context.Context, projectPath string) (*analyzer.AnalysisResult, error)
- func (ca *Analyzer) AnalyzeRemote(_ context.Context, _ map[string][]byte) (*analyzer.RemoteAnalysisResult, error)
- func (ca *Analyzer) RecommendStrategy(ctx context.Context, analysis *analyzer.AnalysisResult, ...) (*analyzer.Strategy, error)
- type Composer
- func (c *Composer) Detect(_ context.Context, dir string) (bool, error)
- func (c *Composer) GetAnalyzer() analyzer.Analyzer
- func (c *Composer) GetManifestFiles() []string
- func (c *Composer) Name() string
- func (c *Composer) Update(ctx context.Context, cfg *languages.UpdateConfig) error
- func (c *Composer) Validate(ctx context.Context, cfg *languages.UpdateConfig) error
- type Lock
- type LockPackage
- type Package
- type UpdateConfig
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLockNotFound = errors.New("composer.lock not found")
ErrLockNotFound indicates composer.lock was not found.
var ErrRemoteAnalysisNotImplemented = errors.New("remote analysis not implemented")
ErrRemoteAnalysisNotImplemented indicates remote analysis is not yet supported.
Functions ¶
func DoUpdate ¶
func DoUpdate(ctx context.Context, packages map[string]*Package, composerPackages []LockPackage, cfg *UpdateConfig) error
DoUpdate performs the actual update of Composer package dependencies.
func RunRequire ¶
func RunRequire(ctx context.Context, name, version, composerRoot string, extraArgs ...string) (string, error)
RunRequire updates a specific package to a precise version. Uses: composer require <package>:<version> --no-interaction Additional args can be passed (e.g., "--no-install" for testing).
func RunRequireDev ¶
func RunRequireDev(ctx context.Context, name, version, composerRoot string, extraArgs ...string) (string, error)
RunRequireDev updates a specific dev package to a precise version. Uses: composer require --dev <package>:<version> --no-interaction Additional args can be passed (e.g., "--no-install" for testing).
Types ¶
type Analyzer ¶
type Analyzer struct{}
Analyzer implements the analyzer.Analyzer interface for PHP Composer projects.
func (*Analyzer) Analyze ¶
func (ca *Analyzer) Analyze(ctx context.Context, projectPath string) (*analyzer.AnalysisResult, error)
Analyze performs dependency analysis on a Composer project.
func (*Analyzer) AnalyzeRemote ¶
func (ca *Analyzer) AnalyzeRemote(_ context.Context, _ map[string][]byte) (*analyzer.RemoteAnalysisResult, error)
AnalyzeRemote performs dependency analysis on remotely-fetched manifest files.
func (*Analyzer) RecommendStrategy ¶
func (ca *Analyzer) RecommendStrategy(ctx context.Context, analysis *analyzer.AnalysisResult, deps []analyzer.Dependency) (*analyzer.Strategy, error)
RecommendStrategy suggests update strategy for Composer dependencies. For Composer, updates are always direct using composer require.
type Composer ¶
type Composer struct{}
Composer implements the BuildTool interface for PHP Composer projects.
func (*Composer) Detect ¶
Detect checks if Composer manifest files exist in the directory.
Example ¶
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/chainguard-dev/omnibump/pkg/languages/php/composer"
)
func main() {
dir, err := os.MkdirTemp("", "composer-example-*")
if err != nil {
fmt.Println("error:", err)
return
}
defer func() { _ = os.RemoveAll(dir) }()
if err := os.WriteFile(filepath.Join(dir, "composer.lock"), []byte(`{"packages":[]}`), 0o644); err != nil {
fmt.Println("error:", err)
return
}
c := &composer.Composer{}
detected, err := c.Detect(context.Background(), dir)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("Detected:", detected)
}
Output: Detected: true
func (*Composer) GetAnalyzer ¶
GetAnalyzer returns the Composer analyzer.
func (*Composer) GetManifestFiles ¶
GetManifestFiles returns Composer manifest files.
Example ¶
package main
import (
"fmt"
"github.com/chainguard-dev/omnibump/pkg/languages/php/composer"
)
func main() {
c := &composer.Composer{}
files := c.GetManifestFiles()
for _, f := range files {
fmt.Println(f)
}
}
Output: composer.json composer.lock
type Lock ¶
type Lock struct {
Packages []lockEntry `json:"packages"`
PackagesDev []lockEntry `json:"packages-dev"`
}
Lock represents the structure of a composer.lock file.
type LockPackage ¶
type LockPackage struct {
Name string `json:"name"`
Version string `json:"version"`
Require []string `json:"require,omitempty"`
}
LockPackage represents a package from composer.lock.
func ParseLock ¶
func ParseLock(r io.Reader) ([]LockPackage, error)
ParseLock parses a composer.lock file and returns the list of packages.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/chainguard-dev/omnibump/pkg/languages/php/composer"
)
func main() {
lockContent := `{
"packages": [
{"name": "monolog/monolog", "version": "3.8.0"},
{"name": "psr/log", "version": "3.0.2"}
],
"packages-dev": [
{"name": "phpunit/phpunit", "version": "11.5.3"}
]
}`
packages, err := composer.ParseLock(strings.NewReader(lockContent))
if err != nil {
fmt.Println("error:", err)
return
}
for _, pkg := range packages {
fmt.Printf("%s: %s\n", pkg.Name, pkg.Version)
}
}
Output: monolog/monolog: 3.8.0 phpunit/phpunit: 11.5.3 psr/log: 3.0.2