Documentation

InstalledVersions
in package

This class is copied in every Composer installed project and available to all

See also https://getcomposer.org/doc/07-runtime.md#installed-versions

To require its presence, you can require composer-runtime-api ^2.0

Tags
final

Table of Contents

$canGetVendors  : bool|null
$installed  : array<string|int, mixed>|null
$installedByVendor  : array<string|int, array<string|int, mixed>>
getAllRawData()  : array<string|int, array<string|int, mixed>>
Returns the raw data of all installed.php which are currently loaded for custom implementations
getInstalledPackages()  : array<string|int, string>
Returns a list of all package names which are present, either by being installed, replaced or provided
getInstalledPackagesByType()  : array<string|int, string>
Returns a list of all package names with a specific type e.g. 'library'
getInstallPath()  : string|null
getPrettyVersion()  : string|null
getRawData()  : array<string|int, array<string|int, mixed>>
Returns the raw installed.php data for custom implementations
getReference()  : string|null
getRootPackage()  : array<string|int, mixed>
getVersion()  : string|null
getVersionRanges()  : string
Returns a version constraint representing all the range(s) which are installed for a given package
isInstalled()  : bool
Checks whether the given package is installed
reload()  : void
Lets you reload the static array from another file
satisfies()  : bool
Checks whether the given package satisfies a version constraint
getInstalled()  : array<string|int, array<string|int, mixed>>

Properties

$installed

private static array<string|int, mixed>|null $installed
Tags
psalm-var

array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array}|null

$installedByVendor

private static array<string|int, array<string|int, mixed>> $installedByVendor = array()
Tags
psalm-var

array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>

Methods

getAllRawData()

Returns the raw data of all installed.php which are currently loaded for custom implementations

public static getAllRawData() : array<string|int, array<string|int, mixed>>
Tags
psalm-return

list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>

Return values
array<string|int, array<string|int, mixed>>

getInstalledPackages()

Returns a list of all package names which are present, either by being installed, replaced or provided

public static getInstalledPackages() : array<string|int, string>
Tags
psalm-return

list

Return values
array<string|int, string>

getInstalledPackagesByType()

Returns a list of all package names with a specific type e.g. 'library'

public static getInstalledPackagesByType(string $type) : array<string|int, string>
Parameters
$type : string
Tags
psalm-return

list

Return values
array<string|int, string>

getInstallPath()

public static getInstallPath(string $packageName) : string|null
Parameters
$packageName : string
Return values
string|null

If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.

getPrettyVersion()

public static getPrettyVersion(string $packageName) : string|null
Parameters
$packageName : string
Return values
string|null

If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present

getRawData()

Returns the raw installed.php data for custom implementations

public static getRawData() : array<string|int, array<string|int, mixed>>
Tags
deprecated

Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.

psalm-return

array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}

Return values
array<string|int, array<string|int, mixed>>

getReference()

public static getReference(string $packageName) : string|null
Parameters
$packageName : string
Return values
string|null

If the package is being replaced or provided but is not really installed, null will be returned as reference

getRootPackage()

public static getRootPackage() : array<string|int, mixed>
Tags
psalm-return

array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}

Return values
array<string|int, mixed>

getVersion()

public static getVersion(string $packageName) : string|null
Parameters
$packageName : string
Return values
string|null

If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present

getVersionRanges()

Returns a version constraint representing all the range(s) which are installed for a given package

public static getVersionRanges(string $packageName) : string

It is easier to use this via isInstalled() with the $constraint argument if you need to check whether a given version of a package is installed, and not just whether it exists

Parameters
$packageName : string
Return values
string

Version constraint usable with composer/semver

isInstalled()

Checks whether the given package is installed

public static isInstalled(string $packageName[, bool $includeDevRequirements = true ]) : bool

This also returns true if the package name is provided or replaced by another package

Parameters
$packageName : string
$includeDevRequirements : bool = true
Return values
bool

reload()

Lets you reload the static array from another file

public static reload(array<string|int, array<string|int, mixed>> $data) : void

This is only useful for complex integrations in which a project needs to use this class but then also needs to execute another project's autoloader in process, and wants to ensure both projects have access to their version of installed.php.

A typical case would be PHPUnit, where it would need to make sure it reads all the data it needs from this class, then call reload() with require $CWD/vendor/composer/installed.php (or similar) as input to make sure the project in which it runs can then also use this class safely, without interference between PHPUnit's dependencies and the project's dependencies.

Parameters
$data : array<string|int, array<string|int, mixed>>

A vendor/composer/installed.php data set

Tags
psalm-param

array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data

Return values
void

satisfies()

Checks whether the given package satisfies a version constraint

public static satisfies(VersionParser $parser, string $packageName, string|null $constraint) : bool

e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:

Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')

Parameters
$parser : VersionParser

Install composer/semver to have access to this class and functionality

$packageName : string
$constraint : string|null

A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package

Return values
bool

getInstalled()

private static getInstalled() : array<string|int, array<string|int, mixed>>
Tags
psalm-return

list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>

Return values
array<string|int, array<string|int, mixed>>

Search results