Skip to content

Commit

Permalink
Deprecated iconv_set_encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
david-infovigo committed Jun 22, 2021
1 parent 09f8ba6 commit 0e9abe4
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions src/MarketplaceWebServiceOrders/Client.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/*******************************************************************************
* Copyright 2009-2021 Amazon Services. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
*
* You may not use this file except in compliance with the License.
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*******************************************************************************
* PHP Version 5
Expand Down Expand Up @@ -413,9 +413,13 @@ private function _convertListOrdersByNextToken($request) {
*/
public function __construct($awsAccessKeyId, $awsSecretAccessKey, $applicationName, $applicationVersion, $config = null)
{
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');
if (PHP_VERSION_ID < 50600) {
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');
} else {
ini_set('default_charset', 'UTF-8');
}

$this->_awsAccessKeyId = $awsAccessKeyId;
$this->_awsSecretAccessKey = $awsSecretAccessKey;
Expand All @@ -432,7 +436,7 @@ private function setUserAgentHeader(
$attributes = array ();
}

$this->_config['UserAgent'] =
$this->_config['UserAgent'] =
$this->constructUserAgentHeader($applicationName, $applicationVersion, $attributes);
}

Expand All @@ -445,7 +449,7 @@ private function constructUserAgentHeader($applicationName, $applicationVersion,
throw new InvalidArgumentException('$applicationVersion cannot be null');
}

$userAgent =
$userAgent =
$this->quoteApplicationName($applicationName)
. '/'
. $this->quoteApplicationVersion($applicationVersion);
Expand Down Expand Up @@ -652,7 +656,7 @@ private function _httpPost(array $parameters)
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_HTTPHEADER, $allHeadersStr);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($config['ProxyHost'] != null && $config['ProxyPort'] != -1)
{
Expand All @@ -677,11 +681,11 @@ private function _httpPost(array $parameters)
curl_close($ch);
return $this->_extractHeadersAndBody($response);
}

/**
* This method will attempt to extract the headers and body of our response.
* We need to split the raw response string by 2 'CRLF's. 2 'CRLF's should indicate the separation of the response header
* from the response body. However in our case we have some circumstances (certain client proxies) that result in
* from the response body. However in our case we have some circumstances (certain client proxies) that result in
* multiple responses concatenated. We could encounter a response like
*
* HTTP/1.1 100 Continue
Expand All @@ -701,22 +705,22 @@ private function _extractHeadersAndBody($response){
//First split by 2 'CRLF'
$responseComponents = preg_split("/(?:\r?\n){2}/", $response, 2);
$body = null;
for ($count = 0;
$count < count($responseComponents) && $body == null;
for ($count = 0;
$count < count($responseComponents) && $body == null;
$count++) {

$headers = $responseComponents[$count];
$responseStatus = $this->_extractHttpStatusCode($headers);
if($responseStatus != null &&

if($responseStatus != null &&
$this->_httpHeadersHaveContent($headers)){

$responseHeaderMetadata = $this->_extractResponseHeaderMetadata($headers);
//The body will be the next item in the responseComponents array
$body = $responseComponents[++$count];
}
}

//If the body is null here then we were unable to parse the response and will throw an exception
if($body == null){
require_once (dirname(__FILE__) . '/Exception.php');
Expand All @@ -726,11 +730,11 @@ private function _extractHeadersAndBody($response){
}

return array(
'Status' => $responseStatus,
'ResponseBody' => $body,
'Status' => $responseStatus,
'ResponseBody' => $body,
'ResponseHeaderMetadata' => $responseHeaderMetadata);
}

/**
* parse the status line of a header string for the proper format and
* return the status code
Expand All @@ -740,14 +744,14 @@ private function _extractHeadersAndBody($response){
* returns String statusCode or null if the status line can't be parsed
*/
private function _extractHttpStatusCode($headers){
$statusCode = null;
$statusCode = null;
if (1 === preg_match("/(\\S+) +(\\d+) +([^\n\r]+)(?:\r?\n|\r)/", $headers, $matches)) {
//The matches array [entireMatchString, protocol, statusCode, the rest]
$statusCode = $matches[2];
$statusCode = $matches[2];
}
return $statusCode;
}

/**
* Tries to determine some valid headers indicating this response
* has content. In this case
Expand All @@ -757,7 +761,7 @@ private function _httpHeadersHaveContent($headers){
return (1 === preg_match("/[cC]ontent-[lL]ength: +(?:\\d+)(?:\\r?\\n|\\r|$)/", $headers) ||
1 === preg_match("/Transfer-Encoding: +(?!identity[\r\n;= ])(?:[^\r\n]+)(?:\r?\n|\r|$)/i", $headers));
}

/**
* extract a ResponseHeaderMetadata object from the raw headers
*/
Expand All @@ -782,7 +786,7 @@ private function _extractResponseHeaderMetadata($rawHeaders){
}
}
}

require_once(dirname(__FILE__) . '/Model/ResponseHeaderMetadata.php');
return new MarketplaceWebServiceOrders_Model_ResponseHeaderMetadata(
$headers['x-mws-request-id'],
Expand Down Expand Up @@ -813,7 +817,7 @@ private function _pauseOnRetry($retries)
$delay = (int) (pow(4, $retries) * 100000);
usleep($delay);
return true;
}
}
return false;
}

Expand Down

0 comments on commit 0e9abe4

Please sign in to comment.