From ccd11e8c83d0301bf8fb494490fa548c4e434643 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Wed, 8 May 2024 15:29:29 +1200 Subject: [PATCH] ENH Add functionality required by other repositories --- src/MetaData.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/MetaData.php b/src/MetaData.php index a180199..ba7fd46 100644 --- a/src/MetaData.php +++ b/src/MetaData.php @@ -148,9 +148,32 @@ public static function getMetaDataForLocksteppedRepos(): array } /** - * Get all metadata about all repositories we have information about + * Get metadata about all repositories we have information about, + * but only if they're supported for the given CMS major version. + * + * @param array $metadata Flat array of repository metadata, e.g. from getAllRepositoryMetaData(false) + * @param bool $keepWildcardMap If true, repositories with a "*" CMS major mapping are kept in the output + */ + public static function removeReposNotInCmsMajor(array $metadata, string|int $cmsMajor, bool $keepWildcardMap = false): array + { + foreach ($metadata as $i => $repos) { + foreach ($repos as $j => $repo) { + if ( + !array_key_exists($cmsMajor, $repo['majorVersionMapping']) && + (!$keepWildcardMap || !array_key_exists('*', $repo['majorVersionMapping'])) + ) { + unset($metadata[$i][$j]); + } + } + } + return $metadata; + } + + /** + * Get all metadata about all repositories we have information about. + * @param bool $categorised If true, output is grouped by category. */ - public static function getAllRepositoryMetaData(): array + public static function getAllRepositoryMetaData(bool $categorised = true): array { if (empty(self::$repositoryMetaData)) { $rawJson = file_get_contents(__DIR__ . '/../repositories.json'); @@ -160,6 +183,9 @@ public static function getAllRepositoryMetaData(): array } self::$repositoryMetaData = $decodedJson; } - return self::$repositoryMetaData; + if ($categorised) { + return self::$repositoryMetaData; + } + return array_merge(...array_values(self::$repositoryMetaData)); } }