Documentation
¶
Overview ¶
Package composer holds what the Composer (PHP) repository formats share: the package naming rules, Composer's version normalization (VersionParser), the composer.json reader for dist archives and the Composer 2 metadata model (p2 documents with the "composer/2.0" minification). The hosted handler uses all of it; the proxy and group repositories reuse the metadata and version parts.
Index ¶
- Constants
- Variables
- func Decode(data []byte) (map[string][]Version, error)
- func DistPath(name, version, ref string) string
- func DistRef(distURL string) (string, bool)
- func EncodeDocument(pkgs map[string][]Version, minify bool) ([]byte, error)
- func IsDev(normalized string) bool
- func MetadataName(file string) (string, bool, bool)
- func Normalize(version string) (string, error)
- func NormalizePublished(version string) (string, error)
- func RelinkMember(versions []Version, name, root string)
- func RelinkSource(versions []Version, name, root string)
- func RenderSource(data []byte, name, root string, keep func(Version) bool) ([]byte, error)
- func ValidName(name string) bool
- func VerifySHA1(r io.Reader, want string) error
- type Dist
- type Kind
- type Manifest
- type Path
- type Release
- type Version
- func Expand(versions []Version) []Version
- func Filter(versions []Version, keep func(Version) bool) []Version
- func FindVersion(versions []Version, version string) (Version, bool)
- func Minify(versions []Version) []Version
- func NewVersion(name string, composerJSON []byte, rel Release) (Version, error)
- func ParseDocument(data []byte, name string) ([]Version, error)
Constants ¶
const (
// MaxManifestBytes bounds composer.json.
MaxManifestBytes = 4 << 20
)
Limits on what ReadArchive accepts from an untrusted dist zip. Only composer.json is ever decompressed, so these bound the central directory parse and that one member.
const MaxNameLen = 255
MaxNameLen is the longest "vendor/package" name.
const MaxVersionLen = 128
MaxVersionLen is the longest version string (and normalized version) stored.
const MinifiedMarker = "composer/2.0"
MinifiedMarker is the value of the "minified" key of a p2 document whose version lists are stored as differences (Composer's MetadataMinifier).
Variables ¶
var ErrChecksum = errors.New("dist does not match its shasum")
ErrChecksum is a dist whose bytes do not match the shasum its source published.
var ErrDocument = errors.New("unusable composer metadata")
ErrDocument is a p2 document that cannot be used: not JSON, without the requested package or without a usable version.
var ErrInvalidArchive = errors.New("invalid dist archive")
ErrInvalidArchive marks a dist zip that cannot be published; its message says what is wrong and is meant for the publisher.
var ErrInvalidVersion = errors.New("invalid version")
ErrInvalidVersion marks a string that is not a Composer version.
var ErrNoneLeft = errors.New("no version left")
ErrNoneLeft is a document whose every version was filtered out.
Functions ¶
func Decode ¶
Decode parses a p2 document into full version entries per package name, expanding a minified one. Numbers decode as json.Number.
func DistPath ¶
DistPath is the path below the repository of the dist of one version: the coordinates and the content reference, so a URL never changes its bytes.
func DistRef ¶
DistRef is the content reference of a dist URL built by DistPath (of this or another repository); false when the URL is not one.
func EncodeDocument ¶
EncodeDocument renders a p2 document; with minify the version lists are stored as differences and the document says so.
func IsDev ¶
IsDev reports whether a normalized version is a development version: a branch ("dev-main") or a numeric branch ("1.9999999.9999999.9999999-dev"). Composer repositories serve those in the "~dev" metadata document and every other version, pre-releases included, in the stable one.
func MetadataName ¶
MetadataName parses the file name of a p2 document ("package.json" or "package~dev.json") into the package part and whether it is the dev document. The last result is false when file is neither.
func Normalize ¶
Normalize ports Composer's VersionParser::normalize: it turns a version as written in a tag or branch ("v1.2.3", "1.0.0-RC1", "dev-main", "1.x-dev") into the form Composer compares ("1.2.3.0", "1.0.0.0-RC1", "dev-main", "1.9999999.9999999.9999999-dev"). It returns ErrInvalidVersion for what Composer rejects.
func NormalizePublished ¶
NormalizePublished validates a version given for an upload and returns its normalized form. Besides what Composer's Normalize accepts it requires a plain version string: no surrounding space, aliases ("x as y"), stability flags ("@dev") or characters that do not belong in a URL path, and a non-empty branch name after "dev-".
func RelinkMember ¶
RelinkMember points the dists of entries a repository of this server served at repository root: the file name of the dist (its content reference) is kept because the member keeps serving it under the same path. An entry whose dist is none of a repository's loses it. The entries are modified.
func RelinkSource ¶
RelinkSource points the dists of entries a source other than this server published at repository root (the absolute URL of a proxy repository, without a trailing slash). The reference and shasum stay the source's, so Composer still verifies what it downloads against them. An entry whose dist cannot be proxied (no dist, another type, no http(s) URL) loses it and is installed from its "source" by Composer. The entries are modified.
func RenderSource ¶
RenderSource turns the p2 document of package name as a source other than this server published it into the document a proxy repository at root serves: only that package, only the versions keep accepts (nil keeps all), with its dists relinked, minified. The filter sees the expanded entries, so a version that inherited its fields in the minified upstream document is judged by what it inherited. ErrNoneLeft when keep rejects every version.
Types ¶
type Dist ¶
type Dist struct {
// URL is the absolute download URL of the zip.
URL string
// SHA1 is the hex SHA-1 of the zip, Composer's "shasum".
SHA1 string
// Reference identifies the archive content ("reference" in Composer's
// lock file and download cache).
Reference string
}
Dist says where a version's archive is and how to check it.
type Kind ¶
type Kind int
Kind is what a request path below a repository names.
const ( // KindRoot is packages.json. KindRoot Kind = iota + 1 // KindMetadata is a p2 document, p2/vendor/name.json or p2/vendor/name~dev.json. KindMetadata // KindList is list.json. KindList // KindSearch is search.json. KindSearch // KindUpload is packages/upload/vendor/name/version (hosted repositories). KindUpload // KindDist is dists/vendor/name/version/ref.zip. KindDist )
The request paths of a Composer repository.
type Manifest ¶
type Manifest struct {
// JSON is composer.json as stored in the archive (a JSON object).
JSON json.RawMessage
// Name is the "name" field, a valid package name.
Name string
// Version is the optional "version" field, "" when absent.
Version string
// Licenses are the identifiers of the "license" field (a string or a list).
Licenses []string
}
Manifest is what a dist zip says about its package: the composer.json it carries, verbatim, and the fields a repository reads from it.
func ReadArchive ¶
ReadArchive reads composer.json from a dist zip: from the archive root, or, when the root has none, from the single top-level directory the whole archive lives in (the layout of GitHub zipballs). It validates the package name.
type Path ¶
type Path struct {
Kind Kind
Name string
// Dev is set on a p2 document of the "~dev" variant.
Dev bool
// Version is the version of an upload or a dist, unescaped.
Version string
// Ref is the content reference of a dist: the part of its file name before ".zip".
Ref string
}
Path is a parsed request path. Name is "vendor/package"; the other fields are set per kind.
type Release ¶
type Release struct {
// Version is the version as published, Normalized its VersionParser form.
Version, Normalized string
// Time is when the version was published.
Time time.Time
Dist Dist
}
Release is the repository's knowledge about one version of a package.
type Version ¶
Version is one version entry of a p2 document: the composer.json fields of the package at that version plus "version", "version_normalized", "time" and "dist". Numbers are decoded as json.Number so they survive a round trip.
func Expand ¶
Expand is Composer's MetadataMinifier::expand: it turns a minified version list, in which every entry after the first carries only what changed, into full entries. The input is not modified.
func Filter ¶ added in v0.16.0
Filter returns the entries of versions for which keep is true, in order.
func FindVersion ¶ added in v0.16.0
FindVersion returns the entry whose "version" is exactly version.
func NewVersion ¶
NewVersion builds the p2 entry of a release from the package's composer.json.
func ParseDocument ¶
ParseDocument decodes a p2 document and returns the full entries of package name. Entries that are not objects or have no usable "version" are dropped; ErrDocument is returned when the document is not JSON, lacks the package or leaves no entry.
func (Version) Published ¶ added in v0.16.0
Published is when the entry's source published the version ("time"); the zero time when it states none or one that does not parse.
func (Version) VersionString ¶
VersionString is the "version" of an entry; "" when it has none.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package composertest builds Composer dist zips for tests.
|
Package composertest builds Composer dist zips for tests. |