Represents a specialized reader for a Composer JSON file.
Description
This class SHALL provide convenient accessors for commonly used
composer.json metadata after reading and caching the file contents.
Consumers SHOULD use this class when they need normalized access to
package-level metadata. The internal data cache MUST reflect the
contents returned by the underlying JSON file reader at construction
time.
Interfaces
Defines the contract for reading and exposing normalized metadata from a Composer `composer.json` file.
Properties
Stores the decoded Composer JSON document contents.
Stores the installed packages configuration.
Methods
Initializes the Composer JSON reader.
Returns the package authors declared in the Composer file.
Returns the autoload configuration for the requested autoload type.
Returns the development autoload configuration for the requested type.
Returns the executable binary declarations from the Composer file.
Returns comment metadata associated with the Composer file.
Returns configuration data from the Composer `config` section.
Returns the package description declared in the Composer file.
Returns the extra configuration section declared in the Composer file.
Returns the funding entries declared in the Composer file.
Returns the package homepage URL declared in the Composer file.
Returns the package keywords declared in the Composer file.
Returns the package license when it can be resolved to a single value.
Returns the minimum stability declared in the Composer file.
Returns the package name declared in the Composer file.
Returns the readme path or reference declared in the Composer file.
Returns the scripts declared in the Composer file.
Returns the package suggestions declared in the Composer file.
Returns the support metadata declared in the Composer file.
Returns the package time metadata as an immutable date-time instance.
Returns the package type declared in the Composer file.
Returns the package version.
Stores the decoded Composer JSON document contents.
private
array<string, mixed>
$data
Description
This property MUST contain the data read from the target Composer file during construction. Consumers SHOULD treat the structure as internal implementation detail and SHALL rely on accessor methods instead of direct access.
Stores the installed packages configuration.
private
array<string, mixed>
$installed
Description
This property MUST contain the data read from the installed packages configuration file during construction. Consumers SHOULD treat the structure as internal implementation detail and SHALL rely on accessor methods instead of direct access.
Initializes the Composer JSON reader.
public
__construct([
string|null
$path = null]) : mixed
Description
When no path is provided, the default Composer file location returned by Composer's factory SHALL be used. The constructor MUST immediately read and cache the JSON document contents so that subsequent accessor methods can operate on the in-memory data.
Parameters
$path
:
string|null
=
null
Description
The absolute or relative path to a Composer JSON file. When omitted, the default Composer file path SHALL be used.
Description
when $path is'nt provided and COMPOSER environment variable is set to a directory
Description
when composer.json can't be parsed
Returns the package authors declared in the Composer file.
public
getAuthors([
bool
$onlyFirstAuthor = false]) : AuthorInterface|iterable<int, AuthorInterface>
Description
This method SHALL normalize each author entry to an AuthorInterface
implementation. When $onlyFirstAuthor is true, the first normalized
author MUST be returned. If no author is declared, an UnderflowException
SHALL be thrown. When $onlyFirstAuthor is false, all normalized
authors MUST be returned as an iterable.
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
Returns the autoload configuration for the requested autoload type.
public
getAutoload([
string|null
$type = null]) : array<string, mixed>
Description
This method SHALL inspect the autoload section and return the
nested configuration for the requested type, such as psr-4.
When the autoload section or the requested type is not defined,
the method MUST return an empty array.
Parameters
$type
:
string|null
=
null
Description
The autoload mapping type to retrieve. This defaults to the complete section when null.
Return values
Description
the autoload configuration for the requested type, or an empty array when unavailable
Returns the development autoload configuration for the requested type.
public
getAutoloadDev([
string|null
$type = null]) : array<string, mixed>
Description
This method SHALL inspect the autoload-dev section and return the
nested configuration for the requested type. When the section or the
requested type is not defined, the method MUST return an empty array.
Parameters
$type
:
string|null
=
null
Description
The development autoload mapping type to retrieve. This defaults to the complete section when null.
Return values
Description
the autoload-dev configuration for the requested type, or an empty array when unavailable
Returns the executable binary declarations from the Composer file.
public
getBin() : string|array<int, string>
Description
This method SHALL return the bin value as declared when it is a
string or an array. If the section is absent or invalid, the method
MUST return an empty array.
Return values
Description
the declared binary path or paths
Returns comment metadata associated with the Composer file.
public
getComments() : array<int|string, mixed>
Description
Since standard Composer JSON does not define a comments section, this
method SHALL return the _comment key when present and valid. When
comment metadata is unavailable, the method MUST return an empty array.
Return values
Description
the comment metadata, or an empty array when unavailable
Returns configuration data from the Composer `config` section.
public
getConfig(
string|null
$config) : array<string, mixed>|string
Description
This method SHALL return the complete config section when $config
is null. When a specific key is requested, the method SHALL return the
matching value if it is an array or a string. Any non-array scalar
value MUST be cast to string. If the section or key is absent, an
empty array SHALL be returned when $config is null, otherwise an
empty string SHALL be returned.
Parameters
$config
:
string|null
Description
the configuration key to retrieve, or null to retrieve the complete config section
Return values
Description
the requested config value or the full config structure, depending on the requested key
Returns the package description declared in the Composer file.
public
getDescription() : string
Description
This method SHALL return the value of the description key when
present. If the description is not defined, the method MUST return
an empty string.
Return values
Description
the package description, or an empty string when undefined
Returns the extra configuration section declared in the Composer file.
public
getExtra([
string|null
$extra = null]) : array<string, mixed>
Description
This method SHALL return the complete extra section when $extra is
null. When a specific extra key is requested, the method SHALL return
the matching value only when that value is an array. If the section or
requested key is absent, the method MUST return an empty array.
Parameters
$extra
:
string|null
=
null
Description
the extra configuration key to retrieve, or null to retrieve the complete extra section
Return values
Description
the extra configuration data, or an empty array when undefined
Returns the funding entries declared in the Composer file.
public
getFunding() : array<int, Funding>
Description
This method SHALL normalize each funding entry into a Funding value object. Invalid or non-array entries MUST be ignored. If the section is absent, the method MUST return an empty array.
Return values
Description
the funding entries, or an empty array when undefined
Returns the package homepage URL declared in the Composer file.
public
getHomepage() : string
Description
This method SHALL return the value of the homepage key when present.
If the homepage is not defined, the method MUST return an empty string.
Return values
Description
the homepage URL, or an empty string when undefined
Returns the package keywords declared in the Composer file.
public
getKeywords() : array<int, string>
Description
This method SHALL return the keywords values in declaration order
whenever available. Non-string values MUST be ignored. If the section
is absent, the method MUST return an empty array.
Return values
Description
the package keywords, or an empty array when undefined
Returns the package license when it can be resolved to a single value.
public
getLicense() : string|null
Description
This method SHALL return the license value directly when it is a
string. When the license is an array containing exactly one item,
that single item SHALL be returned. When the license field is not
present, is empty, or cannot be resolved to exactly one string
value, the method MUST return null.
Return values
Description
the resolved license identifier, or null when no single license value can be determined
Returns the minimum stability declared in the Composer file.
public
getMinimumStability() : string
Description
This method SHALL return the value of the minimum-stability key when
present. If the key is absent, the method MUST return an empty string.
Return values
Description
the minimum stability value
Returns the package name declared in the Composer file.
public
getName() : string
Description
This method SHALL return the value of the name key when present.
If the package name is not defined, the method MUST return an
empty string.
Return values
Description
the package name, or an empty string when undefined
Returns the readme path or reference declared in the Composer file.
public
getReadme() : string
Description
This method SHALL return the value of the readme key when present.
If the readme value is not defined, the method MUST return an empty
string.
Return values
Description
the readme value, or an empty string when undefined
Returns the scripts declared in the Composer file.
public
getScripts() : array<string, mixed>
Description
This method SHALL return the scripts section when present. If the
section is absent or invalid, the method MUST return an empty array.
Return values
Description
the Composer scripts configuration
Returns the package suggestions declared in the Composer file.
public
getSuggest() : array<string, string>
Description
This method SHALL return the suggest section as a string map.
Non-string keys or values MUST be ignored. If the section is absent,
the method MUST return an empty array.
Return values
Description
the package suggestion map
Returns the support metadata declared in the Composer file.
public
getSupport() : SupportInterface
Description
This method SHALL return a SupportInterface implementation built from
the support section. When the section is absent, an empty support
object MUST be returned.
Return values
Description
the support metadata object
Returns the package time metadata as an immutable date-time instance.
public
getTime() : DateTimeImmutable|null
Description
This method SHALL attempt to create a DateTimeImmutable instance from the
time field. When the field is not present or is not a valid date-time
string, the current immutable date-time SHALL be returned.
Return values
Description
the package time metadata as an immutable date-time value
Returns the package type declared in the Composer file.
public
getType() : string
Description
This method SHALL return the value of the type key when present.
If the package type is not defined, the method MUST return an empty
string.
Return values
Description
the package type, or an empty string when undefined
Returns the package version.
public
getVersion() : string
Description
This method SHOULD return the installed package version when it can be
resolved through Composer's installed versions metadata. When that value
cannot be resolved, the method SHALL fall back to the version value
declared in the Composer file. If neither source provides a usable value,
the method MUST return an empty string.
Return values
Description
the package version, or an empty string when undefined