Skip to content

Commit

Permalink
Ensure all of our PUP requests to i18n use a diff User-Agent, as the …
Browse files Browse the repository at this point in the history
…Guzzle one is blocked
  • Loading branch information
bordoni committed Apr 27, 2024
1 parent f61d682 commit 43b61a0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Commands/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
return 0;
}

/**
* Returns default client options.
*
* @return array<string, array<string, string>>
*/
protected function get_default_client_options() {
$version = \StellarWP\Pup\PUP_VERSION;

Check failure on line 71 in src/Commands/I18n.php

View workflow job for this annotation

GitHub Actions / phpstan

Constant StellarWP\Pup\PUP_VERSION not found.
return [
'headers' => [
'User-Agent' => "StellarWP PUP/{$version}",
],
];
}

/**
* Downloads language files.
*
Expand All @@ -85,7 +99,7 @@ protected function download_language_files( I18nConfig $i18n_config ): int {

$io->writeln( "<fg=yellow>Fetching language files for {$options->text_domain} from {$options->url}</>" ); // @phpstan-ignore-line: Those are strings.

$client = new Client();
$client = new Client( $this->get_default_client_options() );

$project_url = $options->url . '/api/projects/' . $options->slug;
$project_res = $client->request( 'GET', $project_url );
Expand Down Expand Up @@ -150,7 +164,7 @@ protected function download_and_save_translation( $options, $translation, $forma

$tried++;

$client = new Client();
$client = new Client( $this->get_default_client_options() );
$request = new Request( 'GET', $translation_url );

$promise = $client->sendAsync( $request )->then( function ( $response ) use ( $translation_url, $options, $translation, $format, $project_url, $tried, $io ) {
Expand Down

0 comments on commit 43b61a0

Please sign in to comment.