function ZipDownloader::download
@inheritDoc
Overrides FileDownloader::download
File
-
vendor/
composer/ composer/ src/ Composer/ Downloader/ ZipDownloader.php, line 43
Class
- ZipDownloader
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\DownloaderCode
public function download(PackageInterface $package, string $path, ?PackageInterface $prevPackage = null, bool $output = true) : PromiseInterface {
if (null === self::$unzipCommands) {
self::$unzipCommands = [];
$finder = new ExecutableFinder();
if (Platform::isWindows() && ($cmd = $finder->find('7z', null, [
'C:\\Program Files\\7-Zip',
]))) {
self::$unzipCommands[] = [
'7z',
$cmd,
'x',
'-bb0',
'-y',
'%file%',
'-o%path%',
];
}
if ($cmd = $finder->find('unzip')) {
self::$unzipCommands[] = [
'unzip',
$cmd,
'-qq',
'%file%',
'-d',
'%path%',
];
}
if (!Platform::isWindows() && ($cmd = $finder->find('7z'))) {
// 7z linux/macOS support is only used if unzip is not present
self::$unzipCommands[] = [
'7z',
$cmd,
'x',
'-bb0',
'-y',
'%file%',
'-o%path%',
];
}
if (!Platform::isWindows() && ($cmd = $finder->find('7zz'))) {
// 7zz linux/macOS support is only used if unzip is not present
self::$unzipCommands[] = [
'7zz',
$cmd,
'x',
'-bb0',
'-y',
'%file%',
'-o%path%',
];
}
}
$procOpenMissing = false;
if (!function_exists('proc_open')) {
self::$unzipCommands = [];
$procOpenMissing = true;
}
if (null === self::$hasZipArchive) {
self::$hasZipArchive = class_exists('ZipArchive');
}
if (!self::$hasZipArchive && !self::$unzipCommands) {
// php.ini path is added to the error message to help users find the correct file
$iniMessage = IniHelper::getMessage();
if ($procOpenMissing) {
$error = "The zip extension is missing and unzip/7z commands cannot be called as proc_open is disabled, skipping.\n" . $iniMessage;
}
else {
$error = "The zip extension and unzip/7z commands are both missing, skipping.\n" . $iniMessage;
}
throw new \RuntimeException($error);
}
if (null === self::$isWindows) {
self::$isWindows = Platform::isWindows();
if (!self::$isWindows && !self::$unzipCommands) {
if ($procOpenMissing) {
$this->io
->writeError("<warning>proc_open is disabled so 'unzip' and '7z' commands cannot be used, zip files are being unpacked using the PHP zip extension.</warning>");
$this->io
->writeError("<warning>This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.</warning>");
$this->io
->writeError("<warning>Enabling proc_open and installing 'unzip' or '7z' (21.01+) may remediate them.</warning>");
}
else {
$this->io
->writeError("<warning>As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension.</warning>");
$this->io
->writeError("<warning>This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.</warning>");
$this->io
->writeError("<warning>Installing 'unzip' or '7z' (21.01+) may remediate them.</warning>");
}
}
}
return parent::download($package, $path, $prevPackage, $output);
}