Skip to content

Commit

Permalink
bug #872 Use relative URLs when index.json provides them (nicolas-gre…
Browse files Browse the repository at this point in the history
…kas)

This PR was merged into the 1.x branch.

Discussion
----------

Use relative URLs when index.json provides them

Fix #868 with help from symfony-tools/recipes-checker@86f5d7f

Best reviewed [ignoring whitespaces](https://github.com/symfony/flex/pull/872/files?w=1).

Commits
-------

c3815a7 Use relative URLs when index.json provides them
  • Loading branch information
nicolas-grekas committed Feb 16, 2022
2 parents b1fb5d5 + c3815a7 commit 787e2e3
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,38 @@ public function getRecipes(array $operations): array
$version = $version[0].'.'.($version[1] ?? '9999999');

foreach (array_reverse($recipeVersions) as $v => $endpoint) {
if (version_compare($version, $v, '>=')) {
$data['locks'][$package->getName()]['version'] = $version;
$data['locks'][$package->getName()]['recipe']['version'] = $v;
if (version_compare($version, $v, '<')) {
continue;
}

if (null !== $recipeRef && isset($this->endpoints[$endpoint]['_links']['archived_recipes_template'])) {
$urls[] = strtr($this->endpoints[$endpoint]['_links']['archived_recipes_template'], [
'{package_dotted}' => str_replace('/', '.', $package->getName()),
'{ref}' => $recipeRef,
]);
$data['locks'][$package->getName()]['version'] = $version;
$data['locks'][$package->getName()]['recipe']['version'] = $v;
$links = $this->endpoints[$endpoint]['_links'];

break;
if (null !== $recipeRef && isset($links['archived_recipes_template'])) {
if (isset($links['archived_recipes_template_relative'])) {
$links['archived_recipes_template'] = preg_replace('{[^/\?]*+(?=\?|$)}', $links['archived_recipes_template_relative'], $endpoint, 1);
}

$urls[] = strtr($this->endpoints[$endpoint]['_links']['recipe_template'], [
$urls[] = strtr($links['archived_recipes_template'], [
'{package_dotted}' => str_replace('/', '.', $package->getName()),
'{package}' => $package->getName(),
'{version}' => $v,
'{ref}' => $recipeRef,
]);

break;
}

if (isset($links['recipes_template_relative'])) {
$links['recipes_template'] = preg_replace('{[^/\?]*+(?=\?|$)}', $links['recipes_template_relative'], $endpoint, 1);
}

$urls[] = strtr($links['recipe_template'], [
'{package_dotted}' => str_replace('/', '.', $package->getName()),
'{package}' => $package->getName(),
'{version}' => $v,
]);

break;
}

continue;
Expand Down

0 comments on commit 787e2e3

Please sign in to comment.