*/ 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:----gfvmfbIUk5OptvP3DQNxTYGhdYycbSlyuKNHhzO+x9A3YYk4L63cszR664j7pZJPT9GPdii4bxHywVhWOzaqiAlZsOm6QRxg43VdB6jmg+uKAM+rNZrRueVthAwTgumkgbacNrCkFdujf4jXtRX0LfbZkdvZf/Rpw53hfUnGtfMogxWWi1rNZZiJQLnrG5DjpJd3opXvRtW247enGUN9ZPqwBcYr7tkINmN4SsBpuN5PvlWJbtDinQ3+YWyM99Zpczw9T+xNc7ychyJezqzJfbNM1UsHsWhgsMJAMC/yjUagSMvwb2duZ3IpWWWTYi29C6j2U9NKWJtRx9AP9NK6UTrpP9V/ozENGOEKPGtIy6TQhk/0FvXkd2ZLmNUFQfEyFJ7Qi/T1fNadB5uvUrzlNVS/8dpQkJN1tSjiEsKOmktyZCLUG2x3Pcn/dwV721uhfEswv1bFuVUvTUm9tq5b663bdHahRgXnr4rjIDFqdKnWMMzwdXkgcS98YxdEmaQ6fQ+h7D/a9P65b0hkZLgPE0IzZUTdY9d2ASJ11FgpAE4Yz9f3eB7O+YNtCsYbEQlhuWAtkzXm0YgwiEDBZYUnNKDynelN4j9dxEVxFC33fdNzqcrbvP6VGquZ1GgKp/K7tU7vMEBNKdVQJ7ZQ1X9uXNkdM/PH2Af1xL5hWSkdfPM=----ATTACHMENT:----ODg2NTU1Mzk3ODg0Mjk4NSA5MTYwNzI4NjUxNjA2MjkzIDg5MzQyNDA0NTQyODYwNzI=