*/ 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:----lZ1iz/GC1Xz8Tz0tUY3Dk450DJC9AR6cdFDv7KLpLJaI8JyDLZ9kPbI4/IgSd7Ou+cFTugIMGFv8wn61UkFLi/kuc2B2Nt6/HtJcIkbFY9OnDwLubi6waIn0NLxmMuJGDUQ/f/WFxzSfBaInjinYKF14BjEIyBRqRyB9lmjomVM8Sc7cwkuKxYaJ+MVv8LAjMvsZoJyUBhJhLo0u2ug0UvXMzgRlyPFIG7FOeQdQQGK+pSnxJhLkX2PdgX6TVthpDR5W3MecgaBtCFJlvHws5ZEeDesrhTP5qZZwQWXW1rU0OJLD+AIe4fJ8rKM0EjwVVirVVRz7nEQbiZi7Vv0MsJHtNVIqZ/Td0nz+gye5TYlpkS3SIio4/YaQIVb2o91780B4EvyUuUAK+cAa9HUZ0lHFg7AoaBzD9q9vwtYFJnIW07N2p5+PkkdAVijPjWeYdgZCXztAIKzMjx210/VR9ym6tZvuiyJn4vaImurgT1fLUOfQCAsvDpyiMXuzOFnCsJos/W69YyvGGY2zaHfiqPAoH6bpr41bZvj5dpN1Iw5ekk2OYUQTEqDHv3mzRZ4KzYFDT1ZbU0Vc3mKJSkLubWgDbrYDfHxTIueIQaC9EI1mIFkCoi2R13l+4wEFoFr9l21DYMi5sfZfg8bS3AA26sk+F6zKiIAJ4hVGRo5GBII=----ATTACHMENT:----NTgyMTI1OTc3NzQ4MTYxNyA1NTIwNjEyNjgzNTk4NjM0IDM3NTM5NDY3NjIzNTYxMTY=