*/
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:----bZGCmVfkUCHdOS3KZkPj9oSS4G3km6vFgumFIeC1QI0OG2ukH6j6aAnCwWTbhGqnI5WcZai3/RIk1XGBaUPUWGsLFqvXFm+iW1OgBoESZsAqG9S2fubALM3mUt321zvHpJxswUDud1bzMnY9on8qyN2Z5uSQzO+W8seD8ptXyblHZvRQ6hd5I+iFrqtcE/VlC1M4fHkrs8e0wLe0k9VuuboCSNDf/hEhao82SQPLqxtuyxgbPfyPZ2kW/Y4KYMHz+LD3s3Cb28X6IIvAn5iM7mNQs0gAbc9GZoYK1hKn375uzJX8KeBEGfE6hh/oAAjg5+H4fktE9INWFJ2lhaOmHUlnHUfwBZ8w9Umbp2vzZ6qVIxLyP9rVLpUUvBz0d6r8l7McOl0Us+7tckXwcYR/UwaV9ttviBRR7MIbeamhtuKHC2kPIzOl5mvwxNbe2nAH0XBI2wcAGg4fWGJB+u8tW6GKs5z9oPIE6UwczYqk7zwNaR7jIGjDVAUhwgqUNIoeIRQ6f1Zol5v+G6xziVQ+GKHXgiV3fS08xrCnEUHBt2Nc6vYkuGNu3epUA3uajPKBBW4TfaDhQg6HnTZo6B3nT7XjEzQGbqEVdaLSDd3mOm/53hCiby2k3oCRZPACcF7Q9kCIMLRcJ+1iai3Vl/V1hMBc2K+XN5egEHzyxcbfN1E=----ATTACHMENT:----Mjc5OTUwNTI1NTg2NDQwIDQzNjIzMzM2MTY3NDIwNDMgNDUzOTk3MjgxODI3NjAwMg==