|
4 | 4 |
|
5 | 5 | namespace Phpcq\RepositoryBuilder;
|
6 | 6 |
|
| 7 | +use Composer\Semver\Comparator; |
7 | 8 | use Phpcq\RepositoryDefinition\AbstractHash;
|
8 | 9 | use Phpcq\RepositoryDefinition\Plugin\PhpFilePluginVersion;
|
9 | 10 | use Phpcq\RepositoryDefinition\Plugin\PluginInterface;
|
10 | 11 | use Phpcq\RepositoryDefinition\Plugin\PluginRequirements;
|
11 | 12 | use Phpcq\RepositoryDefinition\Tool\ToolInterface;
|
12 | 13 | use Phpcq\RepositoryDefinition\Tool\ToolRequirements;
|
| 14 | +use Phpcq\RepositoryDefinition\Tool\ToolVersionInterface; |
13 | 15 | use Phpcq\RepositoryDefinition\VersionRequirementList;
|
14 | 16 | use stdClass;
|
15 | 17 | use Symfony\Component\Filesystem\Filesystem;
|
16 | 18 |
|
17 | 19 | use function array_flip;
|
18 | 20 | use function array_key_exists;
|
| 21 | +use function array_values; |
19 | 22 | use function glob;
|
20 | 23 | use function hash_file;
|
21 | 24 | use function is_array;
|
22 | 25 | use function is_dir;
|
23 | 26 | use function is_string;
|
24 | 27 | use function json_encode;
|
25 | 28 | use function sprintf;
|
| 29 | +use function usort; |
26 | 30 |
|
27 | 31 | use const JSON_UNESCAPED_SLASHES;
|
28 | 32 | use const JSON_UNESCAPED_UNICODE;
|
@@ -139,7 +143,8 @@ private function processTool(ToolInterface $tool): ?array
|
139 | 143 | $data = [
|
140 | 144 | 'tools' => [],
|
141 | 145 | ];
|
142 |
| - foreach ($tool as $version) { |
| 146 | + |
| 147 | + foreach ($this->getToolVersions($tool) as $version) { |
143 | 148 | if (!isset($data['tools'][$name = $tool->getName()])) {
|
144 | 149 | $data['tools'][$name] = [];
|
145 | 150 | }
|
@@ -296,4 +301,21 @@ private function dumpFile(string $fileName, array $contents): void
|
296 | 301 | assert(is_string($encoded));
|
297 | 302 | $this->filesystem->dumpFile($fullFileName, $encoded);
|
298 | 303 | }
|
| 304 | + |
| 305 | + /** @return list<ToolVersionInterface> */ |
| 306 | + private function getToolVersions(ToolInterface $tool): array |
| 307 | + { |
| 308 | + /** @var array<string, ToolVersionInterface> $versions */ |
| 309 | + $versions = []; |
| 310 | + foreach ($tool as $version) { |
| 311 | + $versions[] = $version; |
| 312 | + } |
| 313 | + usort( |
| 314 | + $versions, |
| 315 | + static fn(ToolVersionInterface $first, ToolVersionInterface $second): int |
| 316 | + => Comparator::greaterThanOrEqualTo($first->getVersion(), $second->getVersion()) ? 1 : -1 |
| 317 | + ); |
| 318 | + |
| 319 | + return $versions; |
| 320 | + } |
299 | 321 | }
|
0 commit comments