From f25bfe09c545e62f687a0794080bf5f592fcb909 Mon Sep 17 00:00:00 2001 From: Serge Smertin Date: Sun, 31 Mar 2013 20:51:37 +0200 Subject: [PATCH] added support for nested location of composer.json files within artifacts --- src/Composer/Repository/ArtifactRepository.php | 17 ++++++++++++++--- .../Test/Repository/ArtifactRepositoryTest.php | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/ArtifactRepository.php b/src/Composer/Repository/ArtifactRepository.php index 2da787738..8442ce9ba 100644 --- a/src/Composer/Repository/ArtifactRepository.php +++ b/src/Composer/Repository/ArtifactRepository.php @@ -69,12 +69,23 @@ class ArtifactRepository extends ArrayRepository private function getComposerInformation(\SplFileInfo $file) { - $composerFile = "zip://{$file->getPathname()}#composer.json"; - $json = @file_get_contents($composerFile); - if (!$json) { + $zip = new \ZipArchive(); + $zip->open($file->getPathname()); + + if (0 == $zip->numFiles) { return false; } + $foundFileIndex = $zip->locateName('composer.json', \ZipArchive::FL_NODIR); + if (false === $foundFileIndex) { + return false; + } + + $configurationFileName = $zip->getNameIndex($foundFileIndex); + + $composerFile = "zip://{$file->getPathname()}#$configurationFileName"; + $json = file_get_contents($composerFile); + $package = JsonFile::parseJson($json, $composerFile); $package['dist'] = array( 'type' => 'zip', diff --git a/tests/Composer/Test/Repository/ArtifactRepositoryTest.php b/tests/Composer/Test/Repository/ArtifactRepositoryTest.php index 7ee7a1595..abf3eefd3 100644 --- a/tests/Composer/Test/Repository/ArtifactRepositoryTest.php +++ b/tests/Composer/Test/Repository/ArtifactRepositoryTest.php @@ -22,6 +22,7 @@ class ArtifactRepositoryTest extends TestCase public function testExtractsConfigsFromZipArchives() { $expectedPackages = array( + 'composer/composer-1.0.0-alpha6', 'vendor0/package0-0.0.1', 'vendor1/package2-4.3.2', );