php

package
v0.13.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

View Source
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

func (p *PHP) Detect(ctx context.Context, dir string) (bool, error)

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

func (p *PHP) GetBuildTool(ctx context.Context, dir string) (BuildTool, error)

GetBuildTool returns the detected build tool. This is useful for the analyzer to get build tool-specific analyzers.

func (*PHP) GetManifestFiles

func (p *PHP) GetManifestFiles() []string

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) Name

func (p *PHP) Name() string

Name returns the language identifier.

func (*PHP) SupportsAnalysis

func (p *PHP) SupportsAnalysis() bool

SupportsAnalysis returns true since PHP has analysis capabilities.

func (*PHP) Update

func (p *PHP) Update(ctx context.Context, cfg *languages.UpdateConfig) error

Update performs dependency updates on a PHP project.

func (*PHP) Validate

func (p *PHP) Validate(ctx context.Context, cfg *languages.UpdateConfig) error

Validate checks if the updates were applied successfully.

Directories

Path Synopsis
Package composer implements Composer build tool support for PHP projects within omnibump.
Package composer implements Composer build tool support for PHP projects within omnibump.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL