From 33d0f2a51647d28b9ab637a68cb4fe3217b34f59 Mon Sep 17 00:00:00 2001 From: David Berlioz Date: Tue, 24 Jan 2023 09:25:22 +0100 Subject: [PATCH] #336 rename charset function and add default --- README.md | 2 +- lib/Document.php | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f2fc2df18..5d276da8e 100644 --- a/README.md +++ b/README.md @@ -318,7 +318,7 @@ $charset = "Shift-JIS"; ... // Create feed document $createFeedDocSpec = new Feeds\CreateFeedDocumentSpecification([ - 'content_type' => SellingPartnerApi\Document::get_content_type_with_charset($feedType['contentType'], $charset)] + 'content_type' => SellingPartnerApi\Document::withContentType($feedType['contentType'], $charset)] ]); ... // Upload feed contents to document diff --git a/lib/Document.php b/lib/Document.php index 04fa993ac..be2defb77 100644 --- a/lib/Document.php +++ b/lib/Document.php @@ -245,14 +245,14 @@ public function downloadStream($output = null): StreamInterface { * Uploads data to the document specified in the constructor. * * @param string|resource|StreamInterface|callable|\Iterator $feedData The contents of the feed to be uploaded - * @param ?string $charset An optional charset for the document to upload + * @param string $charset An optional charset for the document to upload * * @return void */ - public function upload($feedData, ?string $charset = null): void { + public function upload($feedData, string $charset = 'utf-8'): void { $response = $this->client->put($this->url, [ RequestOptions::HEADERS => [ - "content-type" => self::get_content_type_with_charset($this->contentType, $charset), + "content-type" => self::withContentType($this->contentType, $charset), "host" => parse_url($this->url, PHP_URL_HOST), ], RequestOptions::BODY => $feedData, @@ -282,13 +282,10 @@ public function __destruct() { * When uploading a document you must use the exact same content-type/charset in createFeedDocument() and upload(). * * @param string $contentType - * @param string|null $charset + * @param string $charset * @return string */ - public static function get_content_type_with_charset(string $contentType, string $charset = null): string { - if ($charset) { - return $contentType . "; charset=$charset"; - } - return $contentType; + public static function withContentType(string $contentType, string $charset = 'utf-8'): string { + return "{$contentType}; charset={$charset}"; } }