Documentation
¶
Overview ¶
Package composer implements dependency extraction for PHP codebases managed by Composer. The lockfile is the richest in mainstream use: resolved versions, the dependency graph, licenses, descriptions, homepages and the exact git commit of every package are all in it, so extraction is offline and licenses need no enrichment at all.
Index ¶
- func ExtractInstalled(fsys fs.FS, opts *api.DecomposerOptions) (*sbom.NodeList, error)
- type ComposerAuthor
- type ComposerDist
- type ComposerJSON
- type ComposerLock
- type ComposerPackage
- type ComposerSource
- type Decomposer
- func (d *Decomposer) DefaultOptions() any
- func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (d *Decomposer) ExtractWithContext(ctx context.Context, opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (d *Decomposer) FindCodeBases(index *code.PathIndex) ([]string, error)
- func (d *Decomposer) GenerationContext() api.GenerationContext
- func (d *Decomposer) Requirements(_ *api.DecomposerOptions) []api.Requirement
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractInstalled ¶
ExtractInstalled reads every installed Composer environment on a filesystem and returns their merged graph, or (nil, nil) when the filesystem holds none.
Types ¶
type ComposerAuthor ¶ added in v0.4.1
type ComposerAuthor struct {
Name string `json:"name"`
Email string `json:"email"`
Homepage string `json:"homepage"`
}
ComposerAuthor is one author of a package.
type ComposerDist ¶
type ComposerDist struct {
Type string `json:"type"`
URL string `json:"url"`
Reference string `json:"reference"`
// Shasum is the archive's SHA-1 — when the registry states one, which
// Packagist does not: its archives are built from the source commit,
// and the commit is the integrity anchor.
Shasum string `json:"shasum"`
}
ComposerDist points at a package's installable archive.
type ComposerJSON ¶
type ComposerJSON struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Homepage string `json:"homepage"`
Require map[string]string `json:"require"`
RequireDev map[string]string `json:"require-dev"`
// RawLicense is a string or a list; Licenses() reads both.
RawLicense json.RawMessage `json:"license"`
}
ComposerJSON is the manifest, read for what the lock does not carry: the project's own identity and which requirements are direct.
func ParseComposerJSON ¶
func ParseComposerJSON(data []byte) (*ComposerJSON, error)
ParseComposerJSON reads a composer.json document.
func ReadComposerJSON ¶
func ReadComposerJSON(workDir string) (*ComposerJSON, error)
ReadComposerJSON reads a composer.json from a directory.
func (*ComposerJSON) Licenses ¶
func (m *ComposerJSON) Licenses() []string
Licenses returns the manifest's license declaration, which the schema allows as one identifier or a list of them.
type ComposerLock ¶
type ComposerLock struct {
// Packages are what the project needs; PackagesDev what development
// additionally needs. The partition is Composer's own.
Packages []*ComposerPackage `json:"packages"`
PackagesDev []*ComposerPackage `json:"packages-dev"`
ContentHash string `json:"content-hash"`
}
ComposerLock is a parsed composer.lock.
func ParseComposerLock ¶
func ParseComposerLock(data []byte) (*ComposerLock, error)
ParseComposerLock reads a composer.lock document.
func ParseInstalledJSON ¶
func ParseInstalledJSON(data []byte) (*ComposerLock, error)
ParseInstalledJSON reads an installed.json document, in either generation's shape, into the lock structure everything else builds from.
func ReadComposerLock ¶
func ReadComposerLock(workDir string) (*ComposerLock, error)
ReadComposerLock reads a composer.lock from a directory.
type ComposerPackage ¶
type ComposerPackage struct {
// Name is vendor/name, Composer's two-part identity.
Name string `json:"name"`
Version string `json:"version"`
// Source is where the package's code lives — for registry packages a
// git repository and the exact commit — and Dist the archive an
// install downloads.
Source ComposerSource `json:"source"`
Dist ComposerDist `json:"dist"`
// Require maps requirement names to constraints: the edges. Platform
// requirements (php, extensions) appear here too, slash-less.
Require map[string]string `json:"require"`
// Replace and Provide name what the package stands in for: other
// packages it replaces, as a framework does its own components, and
// virtual packages it provides, such as psr/log-implementation. A
// requirement on one of those names is met by this package, and the
// name has no entry of its own in the lock.
Replace map[string]string `json:"replace"`
Provide map[string]string `json:"provide"`
License []string `json:"license"`
Description string `json:"description"`
Homepage string `json:"homepage"`
// Authors are who the package says wrote it, as its composer.json
// lists them and the lock copies them: people, or the project or
// company itself. The lock names nobody else for a package, so they
// are who it is supplied by.
Authors []ComposerAuthor `json:"authors"`
}
ComposerPackage is one locked package.
type ComposerSource ¶
type ComposerSource struct {
Type string `json:"type"`
URL string `json:"url"`
Reference string `json:"reference"`
}
ComposerSource points at a package's code.
type Decomposer ¶
type Decomposer struct{}
Decomposer reads dependency data from PHP codebases managed by Composer.
func (*Decomposer) DefaultOptions ¶
func (d *Decomposer) DefaultOptions() any
DefaultOptions returns the driver-level options used when none are set.
func (*Decomposer) Extract ¶
func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)
Extract is ExtractWithContext with a background context, for a caller that has none to give.
func (*Decomposer) ExtractWithContext ¶ added in v0.4.1
func (d *Decomposer) ExtractWithContext(ctx context.Context, opts *api.DecomposerOptions) (*sbom.NodeList, error)
ExtractWithContext reads composer.lock and composer.json and builds the graph.
func (*Decomposer) FindCodeBases ¶
func (d *Decomposer) FindCodeBases(index *code.PathIndex) ([]string, error)
FindCodeBases locates PHP codebases by their composer.lock files.
func (*Decomposer) GenerationContext ¶ added in v0.4.1
func (d *Decomposer) GenerationContext() api.GenerationContext
GenerationContext says in what context the decomposer's data is read: a composer.lock or a vendor directory's installed.json, read as they stand in the source tree.
func (*Decomposer) Requirements ¶
func (d *Decomposer) Requirements(_ *api.DecomposerOptions) []api.Requirement
Requirements returns nothing: extraction is pure Go, offline.