2011-05-06 17:55:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Downloader;
|
|
|
|
|
|
|
|
use Composer\Package\PackageInterface;
|
2011-12-16 21:22:08 +00:00
|
|
|
use Symfony\Component\Process\Process;
|
2011-05-06 17:55:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*/
|
2011-09-28 22:48:17 +00:00
|
|
|
class ZipDownloader extends FileDownloader
|
2011-05-06 17:55:49 +00:00
|
|
|
{
|
2011-09-28 22:48:17 +00:00
|
|
|
protected function extract($file, $path)
|
2011-05-06 17:55:49 +00:00
|
|
|
{
|
|
|
|
if (!class_exists('ZipArchive')) {
|
2011-12-16 21:22:08 +00:00
|
|
|
// try to use unzip on *nix
|
|
|
|
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
|
|
$process = new Process('unzip '.escapeshellarg($file).' -d '.escapeshellarg($path));
|
|
|
|
$process->run();
|
|
|
|
if ($process->isSuccessful()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 22:05:08 +00:00
|
|
|
throw new \RuntimeException('You need the zip extension enabled to use the ZipDownloader');
|
2011-05-06 17:55:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 19:06:52 +00:00
|
|
|
$zipArchive = new \ZipArchive();
|
2011-05-06 17:55:49 +00:00
|
|
|
|
2011-09-28 22:48:17 +00:00
|
|
|
if (true !== ($retval = $zipArchive->open($file))) {
|
|
|
|
throw new \UnexpectedValueException($file.' is not a valid zip archive, got error code '.$retval);
|
2011-05-06 17:55:49 +00:00
|
|
|
}
|
2011-09-28 22:48:17 +00:00
|
|
|
|
|
|
|
$zipArchive->extractTo($path);
|
|
|
|
$zipArchive->close();
|
2011-05-06 17:55:49 +00:00
|
|
|
}
|
2011-09-17 13:12:45 +00:00
|
|
|
}
|