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

Breadcrumb

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

function GitLabDriver::initialize

Extracts information from the repository url.

SSH urls use https by default. Set "secure-http": false on the repository config to use http instead.

@inheritDoc

Overrides VcsDriverInterface::initialize

File

vendor/composer/composer/src/Composer/Repository/Vcs/GitLabDriver.php, line 94

Class

GitLabDriver
Driver for GitLab API, use the Git driver for local checkouts.

Namespace

Composer\Repository\Vcs

Code

public function initialize() : void {
    if (!Preg::isMatch(self::URL_REGEX, $this->url, $match)) {
        throw new \InvalidArgumentException(sprintf('The GitLab repository URL %s is invalid. It must be the HTTP URL of a GitLab project.', $this->url));
    }
    $guessedDomain = $match['domain'] ?? (string) $match['domain2'];
    $configuredDomains = $this->config
        ->get('gitlab-domains');
    $urlParts = explode('/', $match['parts']);
    $this->scheme = in_array($match['scheme'], [
        'https',
        'http',
    ], true) ? $match['scheme'] : (isset($this->repoConfig['secure-http']) && $this->repoConfig['secure-http'] === false ? 'http' : 'https');
    $origin = self::determineOrigin($configuredDomains, $guessedDomain, $urlParts, $match['port']);
    if (false === $origin) {
        throw new \LogicException('It should not be possible to create a gitlab driver with an unparsable origin URL (' . $this->url . ')');
    }
    $this->originUrl = $origin;
    if (is_string($protocol = $this->config
        ->get('gitlab-protocol'))) {
        // https treated as a synonym for http.
        if (!in_array($protocol, [
            'git',
            'http',
            'https',
        ], true)) {
            throw new \RuntimeException('gitlab-protocol must be one of git, http.');
        }
        $this->protocol = $protocol === 'git' ? 'ssh' : 'http';
    }
    if (false !== strpos($this->originUrl, ':') || false !== strpos($this->originUrl, '/')) {
        $this->hasNonstandardOrigin = true;
    }
    $this->namespace = implode('/', $urlParts);
    $this->repository = Preg::replace('#(\\.git)$#', '', $match['repo']);
    $this->cache = new Cache($this->io, $this->config
        ->get('cache-repo-dir') . '/' . $this->originUrl . '/' . $this->namespace . '/' . $this->repository);
    $this->cache
        ->setReadOnly($this->config
        ->get('cache-read-only'));
    $this->fetchProject();
}
RSS feed
Powered by Drupal