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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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')) {
|
|
|
|
throw new \UnexpectedValueException('You need the zip extension enabled to use the ZipDownloader');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|