Skip to content

Commit

Permalink
ENH Add functionality required by other repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 8, 2024
1 parent cde6b55 commit ccd11e8
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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));
}
}

0 comments on commit ccd11e8

Please sign in to comment.