Skip to content

Commit

Permalink
#336 rename charset function and add default
Browse files Browse the repository at this point in the history
  • Loading branch information
quazardous committed Jan 24, 2023
1 parent 3eab82e commit 33d0f2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions lib/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}";
}
}

0 comments on commit 33d0f2a

Please sign in to comment.