Documentation
¶
Overview ¶
Package php implements omnibump support for PHP projects.
It provides automatic detection and management of PHP build tools (currently Composer), enabling dependency updates through omnibump's unified language interface.
The package auto-detects which build tool is in use by examining manifest files in the project directory. Once detected, all operations (update, validate, analyze) are delegated to the appropriate build tool implementation.
Build Tools ¶
The following build tools are supported:
- Composer: detected via composer.lock
Usage ¶
The PHP language is automatically registered via its init function. Use the languages package to access it:
lang, err := languages.Get("php")
if err != nil {
// handle error
}
detected, err := lang.Detect(ctx, "/path/to/project")
Example ¶
package main
import (
"fmt"
"github.com/chainguard-dev/omnibump/pkg/languages"
)
func main() {
// Get the PHP language from the registry.
lang, err := languages.Get("php")
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("Language:", lang.Name())
}
Output: Language: php
Index ¶
- Variables
- type BuildTool
- type PHP
- func (p *PHP) Detect(ctx context.Context, dir string) (bool, error)
- func (p *PHP) GetBuildTool(ctx context.Context, dir string) (BuildTool, error)
- func (p *PHP) GetManifestFiles() []string
- func (p *PHP) Name() string
- func (p *PHP) SupportsAnalysis() bool
- func (p *PHP) Update(ctx context.Context, cfg *languages.UpdateConfig) error
- func (p *PHP) Validate(ctx context.Context, cfg *languages.UpdateConfig) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoBuildToolFound = errors.New("no supported PHP build tool found")
ErrNoBuildToolFound indicates no supported PHP build tool was detected.
Functions ¶
This section is empty.
Types ¶
type BuildTool ¶
type BuildTool interface {
// Name returns the build tool identifier (e.g., "composer")
Name() string
// Detect checks if this build tool is present in the given directory.
// Returns true if manifest files for this build tool are found.
Detect(ctx context.Context, dir string) (bool, error)
// Update performs the dependency update using the provided configuration.
Update(ctx context.Context, cfg *languages.UpdateConfig) error
// Validate checks if the updates were applied successfully.
Validate(ctx context.Context, cfg *languages.UpdateConfig) error
// GetManifestFiles returns the list of manifest files for this build tool
// (e.g., ["composer.json", "composer.lock"] for Composer)
GetManifestFiles() []string
// GetAnalyzer returns an analyzer for this build tool, or nil if not supported.
GetAnalyzer() analyzer.Analyzer
}
BuildTool defines the interface that each PHP build tool must implement. This allows omnibump to support Composer and other PHP build systems with a unified interface.
type PHP ¶
type PHP struct {
// contains filtered or unexported fields
}
PHP implements the Language interface for PHP projects. It auto-detects the build tool (Composer, etc.) and delegates to it.
func (*PHP) Detect ¶
Detect checks if any PHP build tool is present in the directory.
Example ¶
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/chainguard-dev/omnibump/pkg/languages/php"
)
func main() {
// Create a temporary directory with a composer.lock to simulate a PHP project.
dir, err := os.MkdirTemp("", "php-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
}
p := &php.PHP{}
detected, err := p.Detect(context.Background(), dir)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("Detected:", detected)
}
Output: Detected: true
func (*PHP) GetBuildTool ¶
GetBuildTool returns the detected build tool. This is useful for the analyzer to get build tool-specific analyzers.
func (*PHP) GetManifestFiles ¶
GetManifestFiles returns PHP manifest files from the detected build tool.
Example ¶
package main
import (
"fmt"
"github.com/chainguard-dev/omnibump/pkg/languages/php"
)
func main() {
p := &php.PHP{}
files := p.GetManifestFiles()
for _, f := range files {
fmt.Println(f)
}
}
Output: composer.json composer.lock
func (*PHP) SupportsAnalysis ¶
SupportsAnalysis returns true since PHP has analysis capabilities.