ComposerJson
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.
Properties
Stores the decoded Composer JSON document contents.
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 extra configuration section declared in the Composer file.
Returns the package description declared in the Composer file.
Returns the package license when it can be resolved to a single value.
Returns the package name declared in the Composer file.
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.
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.
Returns the package authors declared in the Composer file.
public
getAuthors() : array<string|int, mixed>
Description
This method SHALL return the value of the authors key when
present. If the key is absent, the method MUST return an empty
array.
Return values
Description
the authors list as declared in the Composer file, or an empty array when undefined
Returns the autoload configuration for the requested autoload type.
public
getAutoload([
string
$type = 'psr-4']) : array<string|int, 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
=
'psr-4'
Description
The autoload mapping type to retrieve. This
defaults to psr-4.
Return values
Description
the autoload configuration for the requested type, or an empty array when unavailable
Returns the extra configuration section declared in the Composer file.
public
getExtra() : array<string|int, mixed>
Description
This method SHALL return the value of the extra key when present.
If the key is absent, the method MUST return an empty array.
Return values
Description
the extra configuration data, or an empty array when undefined
Returns the package description declared in the Composer file.
public
getPackageDescription() : 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 package license when it can be resolved to a single value.
public
getPackageLicense() : 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 package name declared in the Composer file.
public
getPackageName() : 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