function PathDownloader::install
@inheritDoc
Overrides FileDownloader::install
File
-
vendor/
composer/ composer/ src/ Composer/ Downloader/ PathDownloader.php, line 81
Class
- PathDownloader
- Download a package from a local path.
Namespace
Composer\DownloaderCode
public function install(PackageInterface $package, string $path, bool $output = true) : PromiseInterface {
$path = Filesystem::trimTrailingSlash($path);
$url = $package->getDistUrl();
if (null === $url) {
throw new \RuntimeException('The package ' . $package->getPrettyName() . ' has no dist url configured, cannot install.');
}
$realUrl = realpath($url);
if (false === $realUrl) {
throw new \RuntimeException('Failed to realpath ' . $url);
}
if (realpath($path) === $realUrl) {
if ($output) {
$this->io
->writeError(" - " . InstallOperation::format($package) . $this->getInstallOperationAppendix($package, $path));
}
return \React\Promise\resolve(null);
}
// Get the transport options with default values
$transportOptions = $package->getTransportOptions() + [
'relative' => true,
];
[
$currentStrategy,
$allowedStrategies,
] = $this->computeAllowedStrategies($transportOptions);
$symfonyFilesystem = new SymfonyFilesystem();
$this->filesystem
->removeDirectory($path);
if ($output) {
$this->io
->writeError(" - " . InstallOperation::format($package) . ': ', false);
}
$isFallback = false;
if (self::STRATEGY_SYMLINK === $currentStrategy) {
try {
if (Platform::isWindows()) {
// Implement symlinks as NTFS junctions on Windows
if ($output) {
$this->io
->writeError(sprintf('Junctioning from %s', $url), false);
}
$this->filesystem
->junction($realUrl, $path);
}
else {
$path = rtrim($path, "/");
if ($output) {
$this->io
->writeError(sprintf('Symlinking from %s', $url), false);
}
if ($transportOptions['relative'] === true) {
$absolutePath = $path;
if (!$this->filesystem
->isAbsolutePath($absolutePath)) {
$absolutePath = Platform::getCwd() . DIRECTORY_SEPARATOR . $path;
}
$shortestPath = $this->filesystem
->findShortestPath($absolutePath, $realUrl, false, true);
$symfonyFilesystem->symlink($shortestPath . '/', $path);
}
else {
$symfonyFilesystem->symlink($realUrl . '/', $path);
}
}
} catch (IOException $e) {
if (in_array(self::STRATEGY_MIRROR, $allowedStrategies, true)) {
if ($output) {
$this->io
->writeError('');
$this->io
->writeError(' <error>Symlink failed, fallback to use mirroring!</error>');
}
$currentStrategy = self::STRATEGY_MIRROR;
$isFallback = true;
}
else {
throw new \RuntimeException(sprintf('Symlink from "%s" to "%s" failed!', $realUrl, $path));
}
}
}
// Fallback if symlink failed or if symlink is not allowed for the package
if (self::STRATEGY_MIRROR === $currentStrategy) {
$realUrl = $this->filesystem
->normalizePath($realUrl);
if ($output) {
$this->io
->writeError(sprintf('%sMirroring from %s', $isFallback ? ' ' : '', $url), false);
}
$iterator = new ArchivableFilesFinder($realUrl, []);
$symfonyFilesystem->mirror($realUrl, $path, $iterator);
}
if ($output) {
$this->io
->writeError('');
}
return \React\Promise\resolve(null);
}