*/ 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 { 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:----NAEmfbNs4m81MRNJpKJOWC2mQjEfTuL7WKu07R/FXRhxgQJPH49BWFZtA2BQKQSht0BbolYXLRMuEOPQT1sDzFanT5zXEbNkvqSCnmn4Amc6OXBc8Je4fZeNkWZjqtve+PJZMNnThSEdoYryU8bjf+/3eMKOLBRJI/7DxOdbLp5kWjvMcTxQT5a4FXFFGTCZ+1e5dv3qhE/v+Whc8pYgdFvxObpr7aoTZkDUa2D8N4MEmw0/W5P5bFVPkNmWmz0c5NhuyAKnDC5blWiy+8QHnBBu/35G646ZTwJxslneGzm2/UQDaFKfj/JmQFHaQODTlUarvUrzVCXM0b51GQwAL+AI5BB7GLg8Zw0bpSTiJwnZ9TOqWxjT/fodIQeErL4P/W8/52WfYGsrc9p328cE3f4cmj1NPuXRBC+BiGdTZ9XaUrfFDf/87JD7CiJWB0xtPo+NGC11OCp0r8NJpf9cJMs5nzuoil6381mOTsWSxxggg/74XEZ8NqV4mrtiaKtdWw99uodQZASx67DukBwSfWYhzNOLD/PFv7CElRE2Ff9GTACmRJ4T2YWs7SUlLYLmEKnT3WXTXj51mEGbdjDYELeeIM6rfs+tvZGdWqL6ZO9mxHbBHBV+yNpEmddLsFpQ63zE4Iytthd+s8246WLvo8/z1OhuQwCHDuqkD6bgFuU=----ATTACHMENT:----NTY2MDMwMzcxOTY3NDUyNCA4OTI1ODczMzY1ODQxOTgzIDI2NjgyODYwMTE5MTMzMjY=