From 43b61a02213d1126809f333b846d42b000132318 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Sat, 27 Apr 2024 14:31:56 -0400 Subject: [PATCH 1/3] Ensure all of our PUP requests to i18n use a diff User-Agent, as the Guzzle one is blocked --- src/Commands/I18n.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Commands/I18n.php b/src/Commands/I18n.php index 8d5aaeb..b2b8562 100644 --- a/src/Commands/I18n.php +++ b/src/Commands/I18n.php @@ -62,6 +62,20 @@ protected function execute( InputInterface $input, OutputInterface $output ) { return 0; } + /** + * Returns default client options. + * + * @return array> + */ + protected function get_default_client_options() { + $version = \StellarWP\Pup\PUP_VERSION; + return [ + 'headers' => [ + 'User-Agent' => "StellarWP PUP/{$version}", + ], + ]; + } + /** * Downloads language files. * @@ -85,7 +99,7 @@ protected function download_language_files( I18nConfig $i18n_config ): int { $io->writeln( "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 ); @@ -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 ) { From 081675f6e10c618511b77cb06f64ade055f02b18 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Sat, 27 Apr 2024 23:45:10 -0400 Subject: [PATCH 2/3] PHPStan fix. --- src/Commands/I18n.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Commands/I18n.php b/src/Commands/I18n.php index b2b8562..d3e29e8 100644 --- a/src/Commands/I18n.php +++ b/src/Commands/I18n.php @@ -5,6 +5,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use StellarWP\Pup\App; +use StellarWP\Pup; use StellarWP\Pup\Command\Command; use StellarWP\Pup\I18nConfig; use Symfony\Component\Console\Input\InputInterface; @@ -68,7 +69,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { * @return array> */ protected function get_default_client_options() { - $version = \StellarWP\Pup\PUP_VERSION; + $version = Pup\PUP_VERSION; return [ 'headers' => [ 'User-Agent' => "StellarWP PUP/{$version}", From ba732aee909ef95a5b945ca5bc1671dfae2093fe Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Sat, 27 Apr 2024 23:49:02 -0400 Subject: [PATCH 3/3] Avoid problems with PHPStan by ensuring the Ignore works on all usages of PUP_VERSION --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 980c1d7..e595008 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -23,4 +23,4 @@ parameters: ignoreErrors: - '#^Constant __PUP_DIR__ not found\.$#' - - '#^Constant PUP_VERSION not found\.$#' + - '#^Constant (.*)PUP_VERSION not found\.$#'