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

Breadcrumb

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

function FilesystemRepository::write

Writes writable repository.

Overrides WritableArrayRepository::write

File

vendor/composer/composer/src/Composer/Repository/FilesystemRepository.php, line 121

Class

FilesystemRepository
Filesystem repository.

Namespace

Composer\Repository

Code

public function write(bool $devMode, InstallationManager $installationManager) {
    $data = [
        'packages' => [],
        'dev' => $devMode,
        'dev-package-names' => [],
    ];
    $dumper = new ArrayDumper();
    // make sure the directory is created so we can realpath it
    // as realpath() does some additional normalizations with network paths that normalizePath does not
    // and we need to find shortest path correctly
    $repoDir = dirname($this->file
        ->getPath());
    $this->filesystem
        ->ensureDirectoryExists($repoDir);
    $repoDir = $this->filesystem
        ->normalizePath(realpath($repoDir));
    $installPaths = [];
    foreach ($this->getCanonicalPackages() as $package) {
        $pkgArray = $dumper->dump($package);
        $path = $installationManager->getInstallPath($package);
        $installPath = null;
        if ('' !== $path && null !== $path) {
            $normalizedPath = $this->filesystem
                ->normalizePath($this->filesystem
                ->isAbsolutePath($path) ? $path : Platform::getCwd() . '/' . $path);
            $installPath = $this->filesystem
                ->findShortestPath($repoDir, $normalizedPath, true);
        }
        $installPaths[$package->getName()] = $installPath;
        $pkgArray['install-path'] = $installPath;
        $data['packages'][] = $pkgArray;
        // only write to the files the names which are really installed, as we receive the full list
        // of dev package names before they get installed during composer install
        if (in_array($package->getName(), $this->devPackageNames, true)) {
            $data['dev-package-names'][] = $package->getName();
        }
    }
    sort($data['dev-package-names']);
    usort($data['packages'], static function ($a, $b) : int {
        return strcmp($a['name'], $b['name']);
    });
    $this->file
        ->write($data);
    if ($this->dumpVersions) {
        $versions = $this->generateInstalledVersions($installationManager, $installPaths, $devMode, $repoDir);
        $this->filesystem
            ->filePutContentsIfModified($repoDir . '/installed.php', '<?php return ' . $this->dumpToPhpCode($versions) . ';' . "\n");
        $installedVersionsClass = file_get_contents(__DIR__ . '/../InstalledVersions.php');
        // this normally should not happen but during upgrades of Composer when it is installed in the project it is a possibility
        if ($installedVersionsClass !== false) {
            $this->filesystem
                ->filePutContentsIfModified($repoDir . '/InstalledVersions.php', $installedVersionsClass);
            \Composer\InstalledVersions::reload($versions);
        }
    }
}
RSS feed
Powered by Drupal