Skip to content
PHP Ecosystem
Explore

InstalledPackages

API reference › Scaffold › Config › InstalledPackages

final readonly classPHPForge\Scaffold\Config\InstalledPackages
Sourcesrc/Config/InstalledPackages.php

Represents the packages Composer installed in a project, read from its vendor/composer/installed.php.

MethodDescriptionDefined by
__construct()Creates an installed-package view from normalized Composer metadata, or an unknown view from null.InstalledPackages
detect() staticReads the installed packages of the project from <vendorDir>/composer/installed.php, then from the Composer\InstalledVersions runtime data when its root package is $projectRoot.InstalledPackages
fromRawData() staticBuilds the list from the array returned by a vendor/composer/installed.php file.InstalledPackages
has()Returns whether $name is installed; false when the installed packages are unknown.InstalledPackages
installPath()Returns the absolute install path of $name, or null when it is not installed or unknown.InstalledPackages
isKnown()Returns whether the installed packages are known.InstalledPackages
version()Returns the installed pretty version of $name, or null when it is not installed or unknown.InstalledPackages
public function __construct(array<string, array{version: string|null, path: string|null}>|null $packages)

Creates an installed-package view from normalized Composer metadata, or an unknown view from null.

Parameters

ParameterTypeDescription
$packagesarray<string, array{version: string|null, path: string|null}>|nullInstalled packages keyed by name, with their pretty version and absolute install path, or null when the installed packages are unknown.
public static function detect(string $vendorDir, string $projectRoot): self

Reads the installed packages of the project from <vendorDir>/composer/installed.php, then from the Composer\InstalledVersions runtime data when its root package is $projectRoot.

Parameters

ParameterTypeDescription
$vendorDirstringAbsolute path to the Composer vendor directory of the project.
$projectRootstringAbsolute path to the project root.

Returns

self: Installed packages, or an unknown list when neither source describes the project.

public static function fromRawData(mixed $data): self

Builds the list from the array returned by a vendor/composer/installed.php file.

Parameters

ParameterTypeDescription
$datamixedDecoded installed data with a versions map; any other value yields an unknown list.

Returns

self: Installed packages that declare an install path, or an unknown list when $data is malformed.

public function has(string $name): bool

Returns whether $name is installed; false when the installed packages are unknown.

Parameters

ParameterTypeDescription
$namestringPackage name to look up.

Returns

bool: true when the package is installed, false when it is not installed or the list is unknown.

public function installPath(string $name): string|null

Returns the absolute install path of $name, or null when it is not installed or unknown.

Parameters

ParameterTypeDescription
$namestringPackage name to look up.

Returns

string|null: Absolute install path, or null when the package is not installed or the list is unknown.

public function isKnown(): bool

Returns whether the installed packages are known.

Returns

bool: true when an installed package source describes the project, false otherwise.

public function version(string $name): string|null

Returns the installed pretty version of $name, or null when it is not installed or unknown.

Parameters

ParameterTypeDescription
$namestringPackage name to look up.

Returns

string|null: Pretty version, or null when it is missing, not installed, or the list is unknown.