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

Breadcrumb

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

function ArrayLoader::getBranchAlias

Retrieves a branch alias (dev-master => 1.0.x-dev for example) if it exists

Parameters

mixed[] $config the entire package config:

Return value

string|null normalized version of the branch alias or null if there is none

1 call to ArrayLoader::getBranchAlias()
ArrayLoader::configureObject in vendor/composer/composer/src/Composer/Package/Loader/ArrayLoader.php

File

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

Class

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

Namespace

Composer\Package\Loader

Code

public function getBranchAlias(array $config) : ?string {
    if (!isset($config['version']) || !is_scalar($config['version'])) {
        throw new \UnexpectedValueException('no/invalid version defined');
    }
    if (!is_string($config['version'])) {
        $config['version'] = (string) $config['version'];
    }
    if (strpos($config['version'], 'dev-') !== 0 && '-dev' !== substr($config['version'], -4)) {
        return null;
    }
    if (isset($config['extra']['branch-alias']) && \is_array($config['extra']['branch-alias'])) {
        foreach ($config['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
            $sourceBranch = (string) $sourceBranch;
            // ensure it is an alias to a -dev package
            if ('-dev' !== substr($targetBranch, -4)) {
                continue;
            }
            // normalize without -dev and ensure it's a numeric branch that is parseable
            if ($targetBranch === VersionParser::DEFAULT_BRANCH_ALIAS) {
                $validatedTargetBranch = VersionParser::DEFAULT_BRANCH_ALIAS;
            }
            else {
                $validatedTargetBranch = $this->versionParser
                    ->normalizeBranch(substr($targetBranch, 0, -4));
            }
            if ('-dev' !== substr($validatedTargetBranch, -4)) {
                continue;
            }
            // ensure that it is the current branch aliasing itself
            if (strtolower($config['version']) !== strtolower($sourceBranch)) {
                continue;
            }
            // If using numeric aliases ensure the alias is a valid subversion
            if (($sourcePrefix = $this->versionParser
                ->parseNumericAliasPrefix($sourceBranch)) && ($targetPrefix = $this->versionParser
                ->parseNumericAliasPrefix($targetBranch)) && stripos($targetPrefix, $sourcePrefix) !== 0) {
                continue;
            }
            return $validatedTargetBranch;
        }
    }
    if (isset($config['default-branch']) && $config['default-branch'] === true && false === $this->versionParser
        ->parseNumericAliasPrefix(Preg::replace('{^v}', '', $config['version']))) {
        return VersionParser::DEFAULT_BRANCH_ALIAS;
    }
    return null;
}

API Navigation

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