Skip to content

Commit 52df8cd

Browse files
Fix handling flex://defaults
1 parent f1e77e6 commit 52df8cd

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Downloader.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
class Downloader
3030
{
3131
private const DEFAULT_ENDPOINTS = [
32-
'https://api.github.com/repos/symfony/recipes/contents/index.json?ref=flex/main' => [],
33-
'https://api.github.com/repos/symfony/recipes-contrib/contents/index.json?ref=flex/main' => [],
32+
'https://api.github.com/repos/symfony/recipes/contents/index.json?ref=flex/main',
33+
'https://api.github.com/repos/symfony/recipes-contrib/contents/index.json?ref=flex/main',
3434
];
3535
private const MAX_LENGTH = 1000;
3636

@@ -63,25 +63,29 @@ public function __construct(Composer $composer, IoInterface $io, $rfs)
6363
$this->endpoints = null;
6464
$this->legacyEndpoint = 'https://flex.symfony.com';
6565
}
66-
} elseif (\is_array($endpoint) || false !== strpos($endpoint, '.json')) {
67-
$this->endpoints = array_fill_keys((array) $endpoint, []);
66+
} elseif (\is_array($endpoint) || false !== strpos($endpoint, '.json') || 'flex://defaults' === $endpoint) {
67+
$this->endpoints = array_values((array) $endpoint);
6868
} else {
6969
$this->legacyEndpoint = rtrim($endpoint, '/');
7070
}
7171

7272
if (false === $endpoint = getenv('SYMFONY_ENDPOINT')) {
7373
// no-op
74-
} elseif (false !== strpos($endpoint, '.json')) {
74+
} elseif (false !== strpos($endpoint, '.json') || 'flex://defaults' === $endpoint) {
7575
$this->endpoints ?? $this->endpoints = self::DEFAULT_ENDPOINTS;
76-
$this->endpoints = [$endpoint => []] + $this->endpoints;
76+
array_unshift($this->endpoints, $endpoint);
7777
$this->legacyEndpoint = null;
7878
} else {
7979
$this->endpoints = null;
8080
$this->legacyEndpoint = rtrim($endpoint, '/');
8181
}
8282

83-
if (null !== $this->endpoints && false !== $i = array_search('flex://defaults', $this->endpoints, true)) {
84-
array_splice($this->endpoints, $i, 1, self::DEFAULT_ENDPOINTS);
83+
if (null !== $this->endpoints) {
84+
if (false !== $i = array_search('flex://defaults', $this->endpoints, true)) {
85+
array_splice($this->endpoints, $i, 1, self::DEFAULT_ENDPOINTS);
86+
}
87+
88+
$this->endpoints = array_fill_keys($this->endpoints, []);
8589
}
8690

8791
$this->io = $io;

0 commit comments

Comments
 (0)