|
23 | 23 | use Php\Pie\DependencyResolver\RequestedPackageAndVersion; |
24 | 24 | use Php\Pie\DependencyResolver\ResolvedPackageRequest; |
25 | 25 | use Php\Pie\DependencyResolver\UnableToResolveRequirement; |
| 26 | +use Php\Pie\Downloading\DownloadUrlMethod; |
26 | 27 | use Php\Pie\ExtensionName; |
27 | 28 | use Php\Pie\Installing\InstallForPhpProject\FindMatchingPackages; |
28 | 29 | use Php\Pie\Platform as PiePlatform; |
|
36 | 37 | use Symfony\Component\Console\Input\InputInterface; |
37 | 38 | use Symfony\Component\Console\Input\InputOption; |
38 | 39 | use Throwable; |
| 40 | +use ValueError; |
39 | 41 | use Webmozart\Assert\Assert; |
40 | 42 |
|
41 | 43 | use function array_key_exists; |
|
44 | 46 | use function assert; |
45 | 47 | use function count; |
46 | 48 | use function explode; |
| 49 | +use function implode; |
47 | 50 | use function is_array; |
48 | 51 | use function is_dir; |
49 | 52 | use function is_string; |
@@ -75,6 +78,7 @@ final class CommandHelper |
75 | 78 | private const OPTION_MAKE_PARALLEL_JOBS = 'make-parallel-jobs'; |
76 | 79 | private const OPTION_SKIP_ENABLE_EXTENSION = 'skip-enable-extension'; |
77 | 80 | private const OPTION_FORCE = 'force'; |
| 81 | + private const OPTION_SUPPRESS_DOWNLOAD_URL_METHOD = 'suppress-download-url-method'; |
78 | 82 | private const OPTION_NO_CACHE = 'no-cache'; |
79 | 83 | private const OPTION_AUTO_INSTALL_BUILD_TOOLS = 'auto-install-build-tools'; |
80 | 84 | private const OPTION_SUPPRESS_BUILD_TOOLS_CHECK = 'no-build-tools-check'; |
@@ -152,6 +156,14 @@ public static function configureDownloadBuildInstallOptions(Command $command, bo |
152 | 156 | 'To attempt to install a version that doesn\'t match the version constraints from the meta-data, for instance to install an older version than recommended, or when the signature is not available.', |
153 | 157 | ); |
154 | 158 |
|
| 159 | + $command->addOption( |
| 160 | + self::OPTION_SUPPRESS_DOWNLOAD_URL_METHOD, |
| 161 | + null, |
| 162 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
| 163 | + 'Do not use the specified download URL methods if they are supported by the extension. May be specified multiple times. Valid values: ' |
| 164 | + . implode(', ', array_map(static fn (DownloadUrlMethod $downloadUrlMethod): string => $downloadUrlMethod->value, DownloadUrlMethod::cases())), |
| 165 | + ); |
| 166 | + |
155 | 167 | $command->addOption( |
156 | 168 | self::OPTION_WORKING_DIRECTORY, |
157 | 169 | 'd', |
@@ -293,6 +305,35 @@ public static function determineForceInstallingPackageVersion(InputInterface $in |
293 | 305 | return $input->hasOption(self::OPTION_FORCE) && $input->getOption(self::OPTION_FORCE); |
294 | 306 | } |
295 | 307 |
|
| 308 | + /** @return list<DownloadUrlMethod> */ |
| 309 | + public static function determineSuppressedDownloadUrlMethods(InputInterface $input): array |
| 310 | + { |
| 311 | + if (! $input->hasOption(self::OPTION_SUPPRESS_DOWNLOAD_URL_METHOD)) { |
| 312 | + return []; |
| 313 | + } |
| 314 | + |
| 315 | + $suppressedDownloadUrlMethods = $input->getOption(self::OPTION_SUPPRESS_DOWNLOAD_URL_METHOD); |
| 316 | + assert(is_array($suppressedDownloadUrlMethods)); |
| 317 | + |
| 318 | + return array_values(array_map( |
| 319 | + static function (mixed $suppressedDownloadUrlMethod): DownloadUrlMethod { |
| 320 | + assert(is_string($suppressedDownloadUrlMethod) && $suppressedDownloadUrlMethod !== ''); |
| 321 | + |
| 322 | + try { |
| 323 | + return DownloadUrlMethod::from($suppressedDownloadUrlMethod); |
| 324 | + } catch (ValueError) { |
| 325 | + throw new InvalidArgumentException(sprintf( |
| 326 | + 'Invalid value "%s" for --%s; valid values are: %s', |
| 327 | + $suppressedDownloadUrlMethod, |
| 328 | + self::OPTION_SUPPRESS_DOWNLOAD_URL_METHOD, |
| 329 | + implode(', ', array_map(static fn (DownloadUrlMethod $downloadUrlMethod): string => $downloadUrlMethod->value, DownloadUrlMethod::cases())), |
| 330 | + )); |
| 331 | + } |
| 332 | + }, |
| 333 | + $suppressedDownloadUrlMethods, |
| 334 | + )); |
| 335 | + } |
| 336 | + |
296 | 337 | public static function autoInstallBuildTools(InputInterface $input): bool |
297 | 338 | { |
298 | 339 | return $input->hasOption(self::OPTION_AUTO_INSTALL_BUILD_TOOLS) |
|
0 commit comments