diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 3f1243ade..59542a4a7 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -122,18 +122,25 @@ class ClassMapGenerator $extraTypes .= '|enum'; } - try { - $contents = Silencer::call('php_strip_whitespace', $path); - if (!$contents) { - if (!file_exists($path)) { - throw new \Exception('File does not exist'); - } - if (!is_readable($path)) { - throw new \Exception('File is not readable'); - } + // Use @ here instead of Silencer to actively suppress 'unhelpful' output + // @link https://github.com/composer/composer/pull/4886 + $contents = @php_strip_whitespace($path); + if (!$contents) { + if (!file_exists($path)) { + $message = 'File at "%s" does not exist, check your classmap definitions'; + } elseif (!is_readable($path)) { + $message = 'File at "%s" is not readable, check its permissions'; + } elseif ('' === trim(file_get_contents($path))) { + // The input file was really empty and thus contains no classes + return array(); + } else { + $message = 'File at "%s" could not be parsed as PHP, it may be binary or corrupted'; + } + $error = error_get_last(); + if (isset($error['message'])) { + $message .= PHP_EOL . 'The following message may be helpful:' . PHP_EOL . $error['message']; } - } catch (\Exception $e) { - throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e); + throw new \RuntimeException(sprintf($message, $path)); } // return early if there is no chance of matching anything in this file diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index 2306b138a..2b1927f6b 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -453,6 +453,10 @@ EOT $errors['openssl'] = true; } + if (extension_loaded('openssl') && OPENSSL_VERSION_NUMBER < 0x1000100f) { + $warnings['openssl_version'] = true; + } + if (!defined('HHVM_VERSION') && !extension_loaded('apcu') && ini_get('apc.enable_cli')) { $warnings['apc_cli'] = true; } @@ -570,6 +574,15 @@ EOT $text .= " Composer works with 5.3.2+ for most people, but there might be edge case issues."; break; + case 'openssl_version': + // Attempt to parse version number out, fallback to whole string value. + $opensslVersion = strstr(trim(strstr(OPENSSL_VERSION_TEXT, ' ')), ' ', true); + $opensslVersion = $opensslVersion ?: OPENSSL_VERSION_TEXT; + + $text = "The OpenSSL library ({$opensslVersion}) used by PHP does not support TLSv1.2 or TLSv1.1.".PHP_EOL; + $text .= "If possible you should upgrade OpenSSL to version 1.0.1 or above."; + break; + case 'xdebug_loaded': $text = "The xdebug extension is loaded, this can slow down Composer a little.".PHP_EOL; $text .= " Disabling it when using Composer is recommended."; diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 13bbb7e09..54a002203 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -12,6 +12,8 @@ namespace Composer\DependencyResolver; +use Composer\Package\CompletePackage; + /** * @author Nils Adermann */ @@ -203,25 +205,40 @@ class Rule if ($targetName === 'php' || $targetName === 'php-64bit' || $targetName === 'hhvm') { // handle php/hhvm if (defined('HHVM_VERSION')) { - $text .= ' -> your HHVM version does not satisfy that requirement.'; + return $text . ' -> your HHVM version does not satisfy that requirement.'; } elseif ($targetName === 'hhvm') { - $text .= ' -> you are running this with PHP and not HHVM.'; + return $text . ' -> you are running this with PHP and not HHVM.'; } else { - $text .= ' -> your PHP version ('. phpversion() .') or value of "config.platform.php" in composer.json does not satisfy that requirement.'; + $packages = $pool->whatProvides($targetName); + $package = count($packages) ? current($packages) : phpversion(); + + if (!($package instanceof CompletePackage)) { + return $text . ' -> your PHP version ('.phpversion().') does not satisfy that requirement.'; + } + + $extra = $package->getExtra(); + + if (!empty($extra['config.platform'])) { + $text .= ' -> your PHP version ('.phpversion().') overriden by "config.platform.php" version ('.$package->getPrettyVersion().') does not satisfy that requirement.'; + } else { + $text .= ' -> your PHP version ('.$package->getPrettyVersion().') does not satisfy that requirement.'; + } + + return $text; } } elseif (0 === strpos($targetName, 'ext-')) { // handle php extensions $ext = substr($targetName, 4); $error = extension_loaded($ext) ? 'has the wrong version ('.(phpversion($ext) ?: '0').') installed' : 'is missing from your system'; - $text .= ' -> the requested PHP extension '.$ext.' '.$error.'.'; + return $text . ' -> the requested PHP extension '.$ext.' '.$error.'.'; } elseif (0 === strpos($targetName, 'lib-')) { // handle linked libs $lib = substr($targetName, 4); - $text .= ' -> the requested linked library '.$lib.' has the wrong version installed or is missing from your system, make sure to have the extension providing it.'; + return $text . ' -> the requested linked library '.$lib.' has the wrong version installed or is missing from your system, make sure to have the extension providing it.'; } else { - $text .= ' -> no matching package found.'; + return $text . ' -> no matching package found.'; } } diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 2f3491fd4..cdf34b6f5 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -512,6 +512,7 @@ class Factory } $am = new Archiver\ArchiveManager($dm); + $am->addArchiver(new Archiver\ZipArchiver); $am->addArchiver(new Archiver\PharArchiver); return $am; diff --git a/src/Composer/Package/Archiver/ZipArchiver.php b/src/Composer/Package/Archiver/ZipArchiver.php new file mode 100644 index 000000000..aaf42ed56 --- /dev/null +++ b/src/Composer/Package/Archiver/ZipArchiver.php @@ -0,0 +1,65 @@ + + * Jordi Boggiano + * + * 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 + */ +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'); + } +} diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 27f52aa65..5016335b0 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -59,6 +59,7 @@ class PlatformRepository extends ArrayRepository $version = $versionParser->normalize($override['version']); $package = new CompletePackage($override['name'], $version, $override['version']); $package->setDescription('Package overridden via config.platform'); + $package->setExtra(array('config.platform' => true)); parent::addPackage($package); } diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index cd3d43260..13cf7cd83 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -113,7 +113,7 @@ class ClassMapGeneratorTest extends TestCase /** * @expectedException \RuntimeException - * @expectedExceptionMessage Could not scan for classes inside + * @expectedExceptionMessage does not exist */ public function testFindClassesThrowsWhenFileDoesNotExist() { diff --git a/tests/Composer/Test/Fixtures/installer/github-issues-4319.test b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test new file mode 100644 index 000000000..56536ed72 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test @@ -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 diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index eaf6caa03..5aa9f862e 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -252,7 +252,7 @@ class InstallerTest extends TestCase $this->assertSame(rtrim($expect), implode("\n", $installationManager->getTrace())); if ($expectOutput) { - $this->assertEquals(rtrim($expectOutput), rtrim($output)); + $this->assertStringMatchesFormat(rtrim($expectOutput), rtrim($output)); } } diff --git a/tests/Composer/Test/Package/Archiver/ZipArchiverTest.php b/tests/Composer/Test/Package/Archiver/ZipArchiverTest.php new file mode 100644 index 000000000..13168573a --- /dev/null +++ b/tests/Composer/Test/Package/Archiver/ZipArchiverTest.php @@ -0,0 +1,64 @@ + + * Jordi Boggiano + * + * 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.'); + } + } +}