InstalledPackages
API reference › Scaffold › Config › InstalledPackages
Represents the packages Composer installed in a project, read from its vendor/composer/installed.php.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates an installed-package view from normalized Composer metadata, or an unknown view from null. | InstalledPackages |
detect() static | Reads the installed packages of the project from <vendorDir>/composer/installed.php, then from the Composer\ runtime data when its root package is $projectRoot. | InstalledPackages |
fromRawData() static | Builds 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 |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”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
| Parameter | Type | Description |
|---|---|---|
$packages | array<string, | Installed packages keyed by name, with their pretty version and absolute install path, or null when the installed packages are unknown. |
detect()
Section titled “detect() ”public static function detect(string $vendorDir, string $projectRoot): selfReads 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
| Parameter | Type | Description |
|---|---|---|
$vendorDir | string | Absolute path to the Composer vendor directory of the project. |
$projectRoot | string | Absolute path to the project root. |
Returns
self: Installed packages, or an unknown list when neither source describes the project.
fromRawData()
Section titled “fromRawData() ”public static function fromRawData(mixed $data): selfBuilds the list from the array returned by a vendor/composer/installed.php file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | Decoded 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.
has()
Section titled “has() ”public function has(string $name): boolReturns whether $name is installed; false when the installed packages are unknown.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Package name to look up. |
Returns
bool: true when the package is installed, false when it is not installed or the list is unknown.
installPath()
Section titled “installPath() ”public function installPath(string $name): string|nullReturns the absolute install path of $name, or null when it is not installed or unknown.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Package name to look up. |
Returns
string|null: Absolute install path, or null when the package is not installed or the list is unknown.
isKnown()
Section titled “isKnown() ”public function isKnown(): boolReturns whether the installed packages are known.
Returns
bool: true when an installed package source describes the project, false otherwise.
version()
Section titled “version() ”public function version(string $name): string|nullReturns the installed pretty version of $name, or null when it is not installed or unknown.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Package name to look up. |
Returns
string|null: Pretty version, or null when it is missing, not installed, or the list is unknown.