function InstalledPackage::createFromArray

Create an installed package object from an array.

Parameters

array $data: The package data.

Return value

static

7 calls to InstalledPackage::createFromArray()
ComposerInspector::getInstalledPackagesList in core/modules/package_manager/src/ComposerInspector.php
Returns the installed packages list.
ComposerInspectorTest::testGetInstalledPackagesList in core/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php
@covers ::getInstalledPackagesList
InstalledPackagesListTest::testCorePackages in core/modules/package_manager/tests/src/Unit/InstalledPackagesListTest.php
@covers ::getCorePackages
InstalledPackagesListTest::testPackageByDrupalProjectName in core/modules/package_manager/tests/src/Kernel/InstalledPackagesListTest.php
@covers \Drupal\package_manager\InstalledPackage::getProjectName @covers ::getPackageByDrupalProjectName
InstalledPackagesListTest::testPackageComparison in core/modules/package_manager/tests/src/Unit/InstalledPackagesListTest.php
@covers ::getPackagesNotIn @covers ::getPackagesWithDifferentVersionsIn

... See full list

File

core/modules/package_manager/src/InstalledPackage.php, line 41

Class

InstalledPackage
A value object that represents an installed Composer package.

Namespace

Drupal\package_manager

Code

public static function createFromArray(array $data) : static {
    $path = isset($data['path']) ? realpath($data['path']) : NULL;
    // Fall back to `library`.
    // @see https://getcomposer.org/doc/04-schema.md#type
    $type = $data['type'] ?? 'library';
    assert(($type === 'metapackage') === is_null($path), 'Metapackage install path must be NULL.');
    return new static($data['name'], $data['version'], $path, $type);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.