ComposerJsonInterface

Interface

Defines the contract for reading and exposing normalized metadata from a Composer `composer.json` file.

Description

This interface provides convenient accessors for commonly used package metadata, including identification, descriptive attributes, licensing, authorship, support channels, funding declarations, autoload mappings, configuration entries, scripts, and additional package-specific sections.

Implementations of this interface MUST read data from a Composer-compatible source and SHALL expose that data through stable, predictable, typed accessors. When a given field is optional in Composer metadata and not declared by the package, implementations SHOULD return an appropriate empty value, nullable value, or default representation as described by each method contract.

Returned values SHOULD preserve the semantic meaning of the underlying composer.json document. Implementations MAY normalize values for interoperability and developer convenience, provided that such normalization does not materially alter the intended meaning of the original metadata.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this interface are to be interpreted as described in RFC 2119.

Table of Contents

Methods

getAuthors()

Returns the package authors declared in the Composer file.

 : AuthorInterface|iterable<int, AuthorInterface>
getAutoload()

Returns the autoload configuration for the requested autoload type.

 : array<string, mixed>
getAutoloadDev()

Returns the development autoload configuration for the requested type.

 : array<string, mixed>
getBin()

Returns the executable binary declarations from the Composer file.

 : string|array<int, string>
getComments()

Returns comment metadata associated with the Composer file.

 : array<int|string, mixed>
getConfig()

Returns configuration data from the Composer `config` section.

 : array<string, mixed>|string
getDescription()

Returns the package description declared in the Composer file.

 : string
getExtra()

Returns the extra configuration section declared in the Composer file.

 : array<string, mixed>
getFunding()

Returns the funding entries declared in the Composer file.

 : array<int, mixed>
getHomepage()

Returns the package homepage URL declared in the Composer file.

 : string
getKeywords()

Returns the package keywords declared in the Composer file.

 : array<int, string>
getLicense()

Returns the package license when it can be resolved to a single value.

 : string|null
getMinimumStability()

Returns the minimum stability declared in the Composer file.

 : string
getName()

Returns the package name declared in the Composer file.

 : string
getReadme()

Returns the readme path or readme reference declared in the Composer file.

 : string
getScripts()

Returns the scripts declared in the Composer file.

 : array<string, mixed>
getSuggest()

Returns the package suggestions declared in the Composer file.

 : array<string, string>
getSupport()

Returns the support metadata declared in the Composer file.

 : SupportInterface
getTime()

Returns the package time metadata as an immutable date-time instance.

 : DateTimeImmutable|null
getType()

Returns the package type declared in the Composer file.

 : string
getVersion()

Returns the package version declared in the Composer file.

 : string
Methods

getAuthors()

Public

Returns the package authors declared in the Composer file.

public getAuthors([ bool  $onlyFirstAuthor = false]) : AuthorInterface|iterable<int, AuthorInterface>

Description

Implementations SHOULD preserve declaration order whenever practical.

When $onlyFirstAuthor is set to true, this method MUST return the first declared author. If no author is declared, the implementation SHOULD handle that condition consistently with its contract and MUST NOT silently return an invalid author representation.

When $onlyFirstAuthor is set to false, this method MUST return all declared authors as an iterable. If the Composer file does not declare any authors, an empty iterable MUST be returned.

Parameters
$onlyFirstAuthor : bool = false

Description

determines whether only the first declared author SHALL be returned instead of the full author list

Return values

Description

the first declared author when $onlyFirstAuthor is true, or the full authors list when $onlyFirstAuthor is false

getAutoload()

Public

Returns the autoload configuration for the requested autoload type.

public getAutoload([ string|null  $type = null]) : array<string, mixed>

Description

The requested type typically refers to an autoload mapping section such as psr-4, psr-0, classmap, or files. When no type is provided, implementations SHOULD use the default Composer autoload type expected by the implementation, which is commonly psr-4.

If the requested autoload type does not exist, implementations SHOULD return an empty array.

Parameters
$type : string|null = null

Description

The autoload mapping type to retrieve. This defaults to psr-4 when null.

Return values
array<string, mixed>

Description

the autoload configuration for the requested type, or an empty array when unavailable

getAutoloadDev()

Public

Returns the development autoload configuration for the requested type.

public getAutoloadDev([ string|null  $type = null]) : array<string, mixed>

Description

The requested type typically refers to an autoload-dev mapping section such as psr-4, psr-0, classmap, or files. When no type is provided, implementations SHOULD use the default autoload-dev type expected by the implementation, which is commonly psr-4.

If the requested development autoload type does not exist, implementations SHOULD return an empty array.

Parameters
$type : string|null = null

Description

The development autoload mapping type to retrieve. This defaults to psr-4 when null.

Return values
array<string, mixed>

Description

the autoload-dev configuration for the requested type, or an empty array when unavailable

getBin()

Public

Returns the executable binary declarations from the Composer file.

public getBin() : string|array<int, string>

Description

Composer bin entries MAY be declared as a single string or as a list of strings. Implementations MUST therefore return either a string or an array, preserving the semantic shape expected by the consumer.

Return values
string|array<int, string>

Description

the declared binary path or paths

getComments()

Public

Returns comment metadata associated with the Composer file.

public getComments() : array<int|string, mixed>

Description

This method SHOULD expose any parsed or implementation-specific comment data that is associated with the source Composer document. When no such comments are available, implementations SHOULD return an empty array.

Return values
array<int|string, mixed>

Description

the comment metadata, or an empty array when unavailable

getConfig()

Public

Returns configuration data from the Composer `config` section.

public getConfig( string|null  $config) : array<string, mixed>|string

Description

When a specific configuration key is provided, implementations SHOULD resolve and return the matching configuration value whenever possible. When the key is null, implementations MAY return the complete configuration structure. The returned value MAY therefore be either an array or a scalar string according to the accessed configuration entry.

Parameters
$config : string|null

Description

the configuration key to retrieve, or null to retrieve the complete config section

Return values
array<string, mixed>|string

Description

the requested config value or the full config structure, depending on the requested key

getDescription()

Public

Returns the package description declared in the Composer file.

public getDescription() : string

Description

Implementations SHOULD return a human-readable summary of the package purpose. When the description field is not defined, an empty string SHOULD be returned.

Return values
string

Description

the package description, or an empty string when undefined

getExtra()

Public

Returns the extra configuration section declared in the Composer file.

public getExtra([ string|null  $extra = null]) : array<string, mixed>

Description

When a specific extra key is provided, implementations SHOULD return the matching extra configuration subset when available. When the key is null, implementations SHOULD return the complete extra section. If the section or requested key is not defined, an empty array SHOULD be returned.

Parameters
$extra : string|null = null

Description

the extra configuration key to retrieve, or null to retrieve the complete extra section

Return values
array<string, mixed>

Description

the extra configuration data, or an empty array when undefined

getFunding()

Public

Returns the funding entries declared in the Composer file.

public getFunding() : array<int, mixed>

Description

Each returned element SHOULD represent a single funding definition from the optional Composer funding section. When no funding entries are declared, implementations SHOULD return an empty array.

Return values
array<int, mixed>

Description

the funding entries, or an empty array when undefined

getHomepage()

Public

Returns the package homepage URL declared in the Composer file.

public getHomepage() : string

Description

Implementations SHOULD return a fully qualified URL when one is available. When the homepage field is not defined, an empty string SHOULD be returned.

Return values
string

Description

the homepage URL, or an empty string when undefined

getKeywords()

Public

Returns the package keywords declared in the Composer file.

public getKeywords() : array<int, string>

Description

Keywords SHOULD be returned in declaration order whenever practical. When the package does not define any keywords, implementations SHOULD return an empty array.

Return values
array<int, string>

Description

the package keywords, or an empty array when undefined

getLicense()

Public

Returns the package license when it can be resolved to a single value.

public getLicense() : string|null

Description

If the underlying Composer metadata contains a single license identifier, this method SHOULD return that identifier. If the metadata contains no license or multiple license values that cannot be reduced to a single unambiguous result, this method MUST return null.

Return values
string|null

Description

the resolved license identifier, or null when no single license value can be determined

getMinimumStability()

Public

Returns the minimum stability declared in the Composer file.

public getMinimumStability() : string

Description

Implementations SHOULD return the configured Composer minimum stability value, such as stable, RC, beta, alpha, or dev. When the field is not explicitly defined, implementations MAY return an empty string or a normalized default value according to implementation policy.

Return values
string

Description

the minimum stability value

getName()

Public

Returns the package name declared in the Composer file.

public getName() : string

Description

The package name SHOULD follow the conventional Composer vendor/package notation when defined. Implementations MAY return an empty string when the name field is absent or cannot be resolved.

Return values
string

Description

the package name, or an empty string when undefined

getReadme()

Public

Returns the readme path or readme reference declared in the Composer file.

public getReadme() : string

Description

Implementations SHOULD return the value exactly as represented by the underlying metadata source whenever possible. When the readme field is absent, an empty string SHOULD be returned.

Return values
string

Description

the readme value, or an empty string when undefined

getScripts()

Public

Returns the scripts declared in the Composer file.

public getScripts() : array<string, mixed>

Description

Implementations SHOULD return the Composer scripts section as a structured array. When no scripts are declared, an empty array SHOULD be returned.

Return values
array<string, mixed>

Description

the Composer scripts configuration

getSuggest()

Public

Returns the package suggestions declared in the Composer file.

public getSuggest() : array<string, string>

Description

The returned array SHOULD represent the Composer suggest section, where keys typically correspond to package names and values describe why the suggested package may be useful. When no suggestions are declared, implementations SHOULD return an empty array.

Return values
array<string, string>

Description

the package suggestion map

getSupport()

Public

Returns the support metadata declared in the Composer file.

public getSupport() : SupportInterface

Description

Implementations MUST return an object implementing SupportInterface. When the support section is absent, the returned object SHOULD represent an empty support definition rather than causing failure.

Return values

Description

the support metadata object

getTime()

Public

Returns the package time metadata as an immutable date-time instance.

public getTime() : DateTimeImmutable|null

Description

This value SHOULD represent the package release or metadata timestamp associated with the Composer file. Implementations MUST return a DateTimeImmutable instance.

Return values
DateTimeImmutable|null

Description

the package time metadata as an immutable date-time value

getType()

Public

Returns the package type declared in the Composer file.

public getType() : string

Description

This value typically identifies how Composer or consuming tools SHOULD interpret the package, such as library, project, or another valid Composer package type. Implementations MAY return an empty string when the type field is absent.

Return values
string

Description

the package type, or an empty string when undefined

getVersion()

Public

Returns the package version declared in the Composer file.

public getVersion() : string

Description

Implementations SHOULD return the version string exactly as declared or as normalized by the underlying Composer metadata source. When no version is explicitly declared, implementations MAY return an empty string.

Return values
string

Description

the package version, or an empty string when undefined