*/
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 = Platform::expandPath($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' => hash_file('sha1', $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:----U6bnt0M4NmtFywYj+YQsab0ksvKg0nPx1fuOPFRSS478WOb+41sjm2IKs2qN6MiZuFunM0BrSnqaoQhLMRNcWo3be23Y9MpN3p1IvcuCm6Oh1vvtu0UR8cVCs7PAo/37QQFcCIiXWm+4z66w3O2yWRvEeXEEUHG+YwAkf3tZUb+G9atH/rGhmLMJv8Upj6tPRKvoRODjIopcjCGPWV8mlegtlm2D270FWLBVxwtxhSnUDnhcyFMVwi3ca5563ixUR2+YjrUQYmm3WB/9MSsDkzMLQxvWL6NTCBrT3Hx8fHQt0HUY6hv3ppBEn0rgIeGyoTH4PF19GdRBHDDJEM1c71M+St+QVQfoBQGTMxCALMTqueZOlxFfT/Qbo2GXfvBbBx9uKBY7R3TWq5ssc6y7J2Ve0J/6PwRtciRY/hvsXQww6Ds6BIBF28T4cX51+v8ioRCUY1qJQPmIY4H6uuF0PFC8xsIAcSnaKmq2k6M7cUP0XplB4c5fqfTbcexcxtGA+5bx5As/Tck6A/2vicVFw9lmIxkuBLPh69OP6+bkDhO0LXTfzL/DzD5iGCgrsGvSqREHb9OUTYj8Ze2We9va60M9w0IW/Z6aclkTFrfnYqu4tu+JmqiSEgECY7Fslo3Wubwfp9OF+5/JPRytLXUBZLyqHjqulFzemXA3sjiKzGE=----ATTACHMENT:----NzE3OTgzMjgyMTUxOTkwNCAxNjk4MjU1MDk4OTMzMTk3IDMyNTAwNTcwNTg1OTk0MA==