*/ class Zip { /** * Gets content of the root composer.json inside a ZIP archive. */ public static function getComposerJson(string $pathToZip): ?string { if (!extension_loaded('zip')) { throw new \RuntimeException('The Zip Util requires PHP\'s zip extension'); } $zip = new \ZipArchive(); if ($zip->open($pathToZip) !== true) { return null; } if (0 === $zip->numFiles) { $zip->close(); return null; } $foundFileIndex = self::locateFile($zip, 'composer.json'); $content = null; $configurationFileName = $zip->getNameIndex($foundFileIndex); $stream = $zip->getStream($configurationFileName); if (false !== $stream) { $content = stream_get_contents($stream); } $zip->close(); return $content; } /** * Find a file by name, returning the one that has the shortest path. * * @throws \RuntimeException */ private static function locateFile(\ZipArchive $zip, string $filename): int { // return root composer.json if it is there and is a file if (false !== ($index = $zip->locateName($filename)) && $zip->getFromIndex($index) !== false) { return $index; } $topLevelPaths = []; for ($i = 0; $i < $zip->numFiles; $i++) { $name = $zip->getNameIndex($i); $dirname = dirname($name); // ignore OSX specific resource fork folder if (strpos($name, '__MACOSX') !== false) { continue; } // handle archives with proper TOC if ($dirname === '.') { $topLevelPaths[$name] = true; if (\count($topLevelPaths) > 1) { throw new \RuntimeException('Archive has more than one top level directories, and no composer.json was found on the top level, so it\'s an invalid archive. Top level paths found were: '.implode(',', array_keys($topLevelPaths))); } continue; } // handle archives which do not have a TOC record for the directory itself if (false === strpos($dirname, '\\') && false === strpos($dirname, '/')) { $topLevelPaths[$dirname.'/'] = true; if (\count($topLevelPaths) > 1) { throw new \RuntimeException('Archive has more than one top level directories, and no composer.json was found on the top level, so it\'s an invalid archive. Top level paths found were: '.implode(',', array_keys($topLevelPaths))); } } } if ($topLevelPaths && false !== ($index = $zip->locateName(key($topLevelPaths).$filename)) && $zip->getFromIndex($index) !== false) { return $index; } throw new \RuntimeException('No composer.json found either at the top level or within the topmost directory'); } } __halt_compiler();----SIGNATURE:----nhtbWnkZVHwMOqoBk6VgTzb1ewJuPb8W8SiMvQUmwlneZ/PW3BSS2rZhDzWKQWl5XM0PqFlP1EEI1yTzDGwD6eGOF1UiaNfY5ds+jsbN9A/WkT2sqi0Zgpp0gg8wWO4o6SofqdstaV67fVl0OdhRfQemPReWQUFtPtTY8uHOcP0b4KkQmLl3jUg/Tdf1gCdcMshspwVTnig4acjEhUN56HM326LxxQNLT8oPGiAoXJZ7Y4M32yFfeVU/8fYuByEm5Qjqh1W0ZkXo/jZSEI9udb2EJ6JY0dbCVQsNjUsi+aK4vnWmgDP4X8MCdgYpHJZkeZlxwbN+oXjyrj7Q33lH5MXzcH1ew7AckQRVOdT5gaUk0WAzKkzTGDHOQcnnsIC13khSnfkkaV9i5NPI6rvB7NxeF/80jj+ZqP5twzFFL3dTeyek4+1GUrtzmGAacA1e9li3e0lbaedDoCkK3Jbr5sCOq0joe7AAg0OtezdRASkCvOHEzkxjoFzK7QIT6+waQ+ekhDqHOB8rZDrfWf/tbb8j23JS5bo9A0+9l3XetRcxtDEq26hayKaDYf3A7B4ytdASC8IL/llcqk4aWjyDKNhoZagr5pqcS7rGDCsSdpd6mGQRbwb+VbjBaJJEnHY5wmCziJDGg35vAwUeOlEU4etEPKRmoXSpMYPFlYUdfwQ=----ATTACHMENT:----NDgxNDY0MTcxMzYzOTE2MyA4MjU1MTU0ODYyODUyMTQ1IDgwODc3Njg2OTIzNTAxNDI=