*/ class ArtifactRepository extends ArrayRepository implements ConfigurableRepositoryInterface { /** @var LoaderInterface */ protected $loader; /** @var string */ protected $lookup; /** @var array{url: string} */ protected $repoConfig; /** @var IOInterface */ private $io; /** * @param array{url: string} $repoConfig */ public function __construct(array $repoConfig, IOInterface $io) { parent::__construct(); if (!extension_loaded('zip')) { throw new \RuntimeException('The artifact repository requires PHP\'s zip extension'); } $this->loader = new ArrayLoader(); $this->lookup = $repoConfig['url']; $this->io = $io; $this->repoConfig = $repoConfig; } public function getRepoName() { return 'artifact repo ('.$this->lookup.')'; } public function getRepoConfig() { return $this->repoConfig; } protected function initialize() { parent::initialize(); $this->scanDirectory($this->lookup); } private function scanDirectory(string $path): void { $io = $this->io; $directory = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS); $iterator = new \RecursiveIteratorIterator($directory); $regex = new \RegexIterator($iterator, '/^.+\.(zip|tar|gz|tgz)$/i'); foreach ($regex as $file) { /* @var $file \SplFileInfo */ if (!$file->isFile()) { continue; } $package = $this->getComposerInformation($file); if (!$package) { $io->writeError("File {$file->getBasename()} doesn't seem to hold a package", true, IOInterface::VERBOSE); continue; } $template = 'Found package %s (%s) in file %s'; $io->writeError(sprintf($template, $package->getName(), $package->getPrettyVersion(), $file->getBasename()), true, IOInterface::VERBOSE); $this->addPackage($package); } } /** * @return ?BasePackage */ private function getComposerInformation(\SplFileInfo $file): ?BasePackage { $json = null; $fileType = null; $fileExtension = pathinfo($file->getPathname(), PATHINFO_EXTENSION); if (in_array($fileExtension, ['gz', 'tar', 'tgz'], true)) { $fileType = 'tar'; } elseif ($fileExtension === 'zip') { $fileType = 'zip'; } else { throw new \RuntimeException('Files with "'.$fileExtension.'" extensions aren\'t supported. Only ZIP and TAR/TAR.GZ/TGZ archives are supported.'); } try { if ($fileType === 'tar') { $json = Tar::getComposerJson($file->getPathname()); } else { $json = Zip::getComposerJson($file->getPathname()); } } catch (\Exception $exception) { $this->io->write('Failed loading package '.$file->getPathname().': '.$exception->getMessage(), false, IOInterface::VERBOSE); } if (null === $json) { return null; } $package = JsonFile::parseJson($json, $file->getPathname().'#composer.json'); $package['dist'] = [ 'type' => $fileType, 'url' => strtr($file->getPathname(), '\\', '/'), 'shasum' => sha1_file($file->getRealPath()), ]; try { $package = $this->loader->load($package); } catch (\UnexpectedValueException $e) { throw new \UnexpectedValueException('Failed loading package in '.$file.': '.$e->getMessage(), 0, $e); } return $package; } } __halt_compiler();----SIGNATURE:----OkcLjJ2o3/OFLZXsaZE3lynst2Pk3XvxjzxO3l+Q1OKLApNpFAYdZRqFGYfcZFBhKVF8N3k5KLTaGD4rY+p0z9r0zeDuxLEkTLntwJFd/l5FdTqyxhMX59gqaFt/HyURHv/ZqVCMet2IXI7p+EcqezHTv148mENWpppAC74EI4P9xh+nmPtNAz0G6EcdU0mlx6IV8AEr1dkwARGv1HetfnFhfIMJjEAVnEJ84hOBmgD8fv18y71wlX4Yy4unalLRwphrkKS+3xLrT9Kx2ThFZ4r7byezUlsbV72O8YiPBg/VO8qhz84Wiz8Bp9P2MMo6gsCPzJXT6rr8WmawD3Wi8Y7lThUT0Q0QZ7+WI2Q/rdRKVuT3KbPvzpjqNHLC3hMCJexMBE9D2oUEyW+HddU+eyDftrSK1ScAKaHHYahcsZjR3jJpXoTNNk1Wk61G7auAOwoLK8VRwm4/Vrfb4X+E8tL2zhrgh9TRG0sa66S9FSCYXYHNrMh7Fa300aweaQg5UMZrKuvVz9rWOpR9gfKIacY6pOFGA/6JbCSpN0QkPCm70WKktAO2agEle+w8euz0tllvLmbg0eMz+1XzSVngyve/E+8+u8LDBInK/6LDO3IbarPKpgHtcekmwrT9/FmLTrbUcrFRAkP6Szrt0tJwPVQVINo4Rdp91Mu9OW7qlkM=----ATTACHMENT:----MjE0MDY0MzI5NzYyMDM1MiA1NDQwODQzNjUwMzU2OTc5IDk1MjY0MTQ1Mzc5Nzg1Mw==