Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ArrayLoader.php

function ArrayLoader::createObject

@template PackageClass of CompletePackage

@phpstan-param class-string<PackageClass> $class

Parameters

mixed[] $config package data:

string $class FQCN to be instantiated:

Return value

CompletePackage|RootPackage

2 calls to ArrayLoader::createObject()
ArrayLoader::load in vendor/composer/composer/src/Composer/Package/Loader/ArrayLoader.php
@inheritDoc
ArrayLoader::loadPackages in vendor/composer/composer/src/Composer/Package/Loader/ArrayLoader.php

File

vendor/composer/composer/src/Composer/Package/Loader/ArrayLoader.php, line 109

Class

ArrayLoader
@author Konstantin Kudryashiv <ever.zet@gmail.com> @author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Package\Loader

Code

private function createObject(array $config, string $class) : CompletePackage {
    if (!isset($config['name'])) {
        throw new \UnexpectedValueException('Unknown package has no name defined (' . json_encode($config) . ').');
    }
    if (!isset($config['version']) || !is_scalar($config['version'])) {
        throw new \UnexpectedValueException('Package ' . $config['name'] . ' has no version defined.');
    }
    if (!is_string($config['version'])) {
        $config['version'] = (string) $config['version'];
    }
    // handle already normalized versions
    if (isset($config['version_normalized']) && is_string($config['version_normalized'])) {
        $version = $config['version_normalized'];
        // handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEFAULT_BRANCH_ALIAS, we renormalize it
        if ($version === VersionParser::DEFAULT_BRANCH_ALIAS) {
            $version = $this->versionParser
                ->normalize($config['version']);
        }
    }
    else {
        $version = $this->versionParser
            ->normalize($config['version']);
    }
    return new $class($config['name'], $version, $config['version']);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal