minor php code improvement

This commit is contained in:
wing328
2016-03-29 20:59:56 +08:00
parent 9d5d047e46
commit 02ac7d93c5
23 changed files with 206 additions and 218 deletions

View File

@@ -259,7 +259,7 @@ class ApiClient
*
* @return string Accept (e.g. application/json)
*/
public static function selectHeaderAccept($accept)
public function selectHeaderAccept($accept)
{
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
return null;
@@ -277,7 +277,7 @@ class ApiClient
*
* @return string Content-Type (e.g. application/json)
*/
public static function selectHeaderContentType($content_type)
public function selectHeaderContentType($content_type)
{
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
return 'application/json';
@@ -299,9 +299,9 @@ class ApiClient
{
// ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986
$headers = array();
$key = ''; // [+]
$key = '';
foreach(explode("\n", $raw_headers) as $i => $h)
foreach(explode("\n", $raw_headers) as $h)
{
$h = explode(':', $h, 2);
@@ -311,26 +311,22 @@ class ApiClient
$headers[$h[0]] = trim($h[1]);
elseif (is_array($headers[$h[0]]))
{
// $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-]
// $headers[$h[0]] = $tmp; // [-]
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+]
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1])));
}
else
{
// $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-]
// $headers[$h[0]] = $tmp; // [-]
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+]
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1])));
}
$key = $h[0]; // [+]
$key = $h[0];
}
else
{
if (substr($h[0], 0, 1) == "\t")
$headers[$key] .= "\r\n\t".trim($h[0]);
elseif (!$key)
$headers[0] = trim($h[0]);trim($h[0]);
}
else // [+]
{ // [+]
if (substr($h[0], 0, 1) == "\t") // [+]
$headers[$key] .= "\r\n\t".trim($h[0]); // [+]
elseif (!$key) // [+]
$headers[0] = trim($h[0]);trim($h[0]); // [+]
} // [+]
}
return $headers;