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\.$#' diff --git a/src/Commands/I18n.php b/src/Commands/I18n.php index 8d5aaeb..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; @@ -62,6 +63,20 @@ protected function execute( InputInterface $input, OutputInterface $output ) { return 0; } + /** + * Returns default client options. + * + * @return array> + */ + protected function get_default_client_options() { + $version = Pup\PUP_VERSION; + return [ + 'headers' => [ + 'User-Agent' => "StellarWP PUP/{$version}", + ], + ]; + } + /** * Downloads language files. * @@ -85,7 +100,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 +165,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 ) {