API - XOOPS 2.5.11 Beta 2
By monxoops.fr
InstalledVersions Class Reference

Static Public Member Functions

static getInstalledPackages ()
 
static getInstalledPackagesByType ($type)
 
static isInstalled ($packageName, $includeDevRequirements=true)
 
static satisfies (VersionParser $parser, $packageName, $constraint)
 
static getVersionRanges ($packageName)
 
static getVersion ($packageName)
 
static getPrettyVersion ($packageName)
 
static getReference ($packageName)
 
static getInstallPath ($packageName)
 
static getRootPackage ()
 
static getRawData ()
 
static getAllRawData ()
 
static reload ($data)
 

Detailed Description

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

Member Function Documentation

◆ getAllRawData()

static getAllRawData ( )
static

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

Returns
array[] @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>

◆ getInstalledPackages()

static getInstalledPackages ( )
static

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

Returns
string[] @psalm-return list<string>

◆ getInstalledPackagesByType()

static getInstalledPackagesByType (   $type)
static

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

Parameters
string$type
Returns
string[] @psalm-return list<string>

◆ getInstallPath()

static getInstallPath (   $packageName)
static
Parameters
string$packageName
Returns
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()

static getPrettyVersion (   $packageName)
static
Parameters
string$packageName
Returns
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()

static getRawData ( )
static

Returns the raw installed.php data for custom implementations

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.
Returns
array[] @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}

◆ getReference()

static getReference (   $packageName)
static
Parameters
string$packageName
Returns
string|null If the package is being replaced or provided but is not really installed, null will be returned as reference

◆ getRootPackage()

static getRootPackage ( )
static
Returns
array @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}

◆ getVersion()

static getVersion (   $packageName)
static
Parameters
string$packageName
Returns
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()

static getVersionRanges (   $packageName)
static

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

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
string$packageName
Returns
string Version constraint usable with composer/semver

◆ isInstalled()

static isInstalled (   $packageName,
  $includeDevRequirements = true 
)
static

Checks whether the given package is installed

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

Parameters
string$packageName
bool$includeDevRequirements
Returns
bool

◆ reload()

static reload (   $data)
static

Lets you reload the static array from another file

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
array[]$dataA vendor/composer/installed.php data set
Returns
void

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

◆ satisfies()

static satisfies ( VersionParser  $parser,
  $packageName,
  $constraint 
)
static

Checks whether the given package satisfies a version constraint

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
VersionParser$parserInstall composer/semver to have access to this class and functionality
string$packageName
string | null$constraintA version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
Returns
bool

The documentation for this class was generated from the following file: