Merge branch 'master' of https://github.com/composer/composer into pull-4690
commit
017a9af672
@ -0,0 +1,65 @@
|
|||||||
|
<?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\Package\Archiver;
|
||||||
|
|
||||||
|
use ZipArchive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jan Prieser <jan@prieser.net>
|
||||||
|
*/
|
||||||
|
class ZipArchiver implements ArchiverInterface
|
||||||
|
{
|
||||||
|
protected static $formats = array(
|
||||||
|
'zip' => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function archive($sources, $target, $format, array $excludes = array())
|
||||||
|
{
|
||||||
|
$sources = realpath($sources);
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
$res = $zip->open($target, ZipArchive::CREATE);
|
||||||
|
if ($res === true) {
|
||||||
|
$files = new ArchivableFilesFinder($sources, $excludes);
|
||||||
|
foreach($files as $file) {
|
||||||
|
/** @var $file \SplFileInfo */
|
||||||
|
$filepath = $file->getPath()."/".$file->getFilename();
|
||||||
|
$localname = str_replace($sources."/", '', $filepath);
|
||||||
|
$zip->addFile($filepath, $localname);
|
||||||
|
}
|
||||||
|
if ($zip->close()) {
|
||||||
|
return $target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$message = sprintf("Could not create archive '%s' from '%s': %s",
|
||||||
|
$target,
|
||||||
|
$sources,
|
||||||
|
$zip->getStatusString()
|
||||||
|
);
|
||||||
|
throw new \RuntimeException($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supports($format, $sourceType)
|
||||||
|
{
|
||||||
|
return isset(static::$formats[$format]) && $this->compressionAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function compressionAvailable() {
|
||||||
|
return class_exists('ZipArchive');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
--TEST--
|
||||||
|
|
||||||
|
See Github issue #4319 ( github.com/composer/composer/issues/4319 ).
|
||||||
|
|
||||||
|
Present a clear error message when config.platform.php version results in a conflict rule.
|
||||||
|
|
||||||
|
--CONDITION--
|
||||||
|
!defined('HHVM_VERSION')
|
||||||
|
|
||||||
|
--COMPOSER--
|
||||||
|
{
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "package",
|
||||||
|
"package": [
|
||||||
|
{ "name": "a", "version": "1.0.0", "require": { "php": "5.5" } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"a": "~1.0"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"platform": {
|
||||||
|
"php": "5.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
--RUN--
|
||||||
|
install
|
||||||
|
|
||||||
|
--EXPECT-OUTPUT--
|
||||||
|
Loading composer repositories with package information
|
||||||
|
Installing dependencies (including require-dev)
|
||||||
|
Your requirements could not be resolved to an installable set of packages.
|
||||||
|
|
||||||
|
Problem 1
|
||||||
|
- Installation request for a ~1.0 -> satisfiable by a[1.0.0].
|
||||||
|
- a 1.0.0 requires php 5.5 -> your PHP version (%s) overriden by "config.platform.php" version (5.3) does not satisfy that requirement.
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
|
||||||
|
--EXPECT-EXIT-CODE--
|
||||||
|
2
|
@ -0,0 +1,64 @@
|
|||||||
|
<?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\Test\Package\Archiver;
|
||||||
|
|
||||||
|
use Composer\Package\Archiver\ZipArchiver;
|
||||||
|
|
||||||
|
class ZipArchiverTest extends ArchiverTest
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testZipArchive()
|
||||||
|
{
|
||||||
|
// Set up repository
|
||||||
|
$this->setupDummyRepo();
|
||||||
|
$package = $this->setupPackage();
|
||||||
|
$target = sys_get_temp_dir().'/composer_archiver_test.zip';
|
||||||
|
|
||||||
|
// Test archive
|
||||||
|
$archiver = new ZipArchiver();
|
||||||
|
$archiver->archive($package->getSourceUrl(), $target, 'zip');
|
||||||
|
$this->assertFileExists($target);
|
||||||
|
|
||||||
|
unlink($target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a local dummy repository to run tests against!
|
||||||
|
*/
|
||||||
|
protected function setupDummyRepo()
|
||||||
|
{
|
||||||
|
$currentWorkDir = getcwd();
|
||||||
|
chdir($this->testDir);
|
||||||
|
|
||||||
|
$this->writeFile('file.txt', 'content', $currentWorkDir);
|
||||||
|
$this->writeFile('foo/bar/baz', 'content', $currentWorkDir);
|
||||||
|
$this->writeFile('foo/bar/ignoreme', 'content', $currentWorkDir);
|
||||||
|
$this->writeFile('x/baz', 'content', $currentWorkDir);
|
||||||
|
$this->writeFile('x/includeme', 'content', $currentWorkDir);
|
||||||
|
|
||||||
|
chdir($currentWorkDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function writeFile($path, $content, $currentWorkDir)
|
||||||
|
{
|
||||||
|
if (!file_exists(dirname($path))) {
|
||||||
|
mkdir(dirname($path), 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = file_put_contents($path, 'a');
|
||||||
|
if (false === $result) {
|
||||||
|
chdir($currentWorkDir);
|
||||||
|
throw new \RuntimeException('Could not save file.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue