Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/guzzleht.../guzzle/src
File: MessageFormatter.php
<?php
[0] Fix | Delete
namespace GuzzleHttp;
[1] Fix | Delete
[2] Fix | Delete
use Psr\Http\Message\MessageInterface;
[3] Fix | Delete
use Psr\Http\Message\RequestInterface;
[4] Fix | Delete
use Psr\Http\Message\ResponseInterface;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Formats log messages using variable substitutions for requests, responses,
[8] Fix | Delete
* and other transactional data.
[9] Fix | Delete
*
[10] Fix | Delete
* The following variable substitutions are supported:
[11] Fix | Delete
*
[12] Fix | Delete
* - {request}: Full HTTP request message
[13] Fix | Delete
* - {response}: Full HTTP response message
[14] Fix | Delete
* - {ts}: ISO 8601 date in GMT
[15] Fix | Delete
* - {date_iso_8601} ISO 8601 date in GMT
[16] Fix | Delete
* - {date_common_log} Apache common log date using the configured timezone.
[17] Fix | Delete
* - {host}: Host of the request
[18] Fix | Delete
* - {method}: Method of the request
[19] Fix | Delete
* - {uri}: URI of the request
[20] Fix | Delete
* - {version}: Protocol version
[21] Fix | Delete
* - {target}: Request target of the request (path + query + fragment)
[22] Fix | Delete
* - {hostname}: Hostname of the machine that sent the request
[23] Fix | Delete
* - {code}: Status code of the response (if available)
[24] Fix | Delete
* - {phrase}: Reason phrase of the response (if available)
[25] Fix | Delete
* - {error}: Any error messages (if available)
[26] Fix | Delete
* - {req_header_*}: Replace `*` with the lowercased name of a request header to add to the message
[27] Fix | Delete
* - {res_header_*}: Replace `*` with the lowercased name of a response header to add to the message
[28] Fix | Delete
* - {req_headers}: Request headers
[29] Fix | Delete
* - {res_headers}: Response headers
[30] Fix | Delete
* - {req_body}: Request body
[31] Fix | Delete
* - {res_body}: Response body
[32] Fix | Delete
*/
[33] Fix | Delete
class MessageFormatter
[34] Fix | Delete
{
[35] Fix | Delete
/**
[36] Fix | Delete
* Apache Common Log Format.
[37] Fix | Delete
* @link http://httpd.apache.org/docs/2.4/logs.html#common
[38] Fix | Delete
* @var string
[39] Fix | Delete
*/
[40] Fix | Delete
const CLF = "{hostname} {req_header_User-Agent} - [{date_common_log}] \"{method} {target} HTTP/{version}\" {code} {res_header_Content-Length}";
[41] Fix | Delete
const DEBUG = ">>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{error}";
[42] Fix | Delete
const SHORT = '[{ts}] "{method} {target} HTTP/{version}" {code}';
[43] Fix | Delete
[44] Fix | Delete
/** @var string Template used to format log messages */
[45] Fix | Delete
private $template;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* @param string $template Log message template
[49] Fix | Delete
*/
[50] Fix | Delete
public function __construct($template = self::CLF)
[51] Fix | Delete
{
[52] Fix | Delete
$this->template = $template ?: self::CLF;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Returns a formatted message string.
[57] Fix | Delete
*
[58] Fix | Delete
* @param RequestInterface $request Request that was sent
[59] Fix | Delete
* @param ResponseInterface $response Response that was received
[60] Fix | Delete
* @param \Exception $error Exception that was received
[61] Fix | Delete
*
[62] Fix | Delete
* @return string
[63] Fix | Delete
*/
[64] Fix | Delete
public function format(
[65] Fix | Delete
RequestInterface $request,
[66] Fix | Delete
ResponseInterface $response = null,
[67] Fix | Delete
\Exception $error = null
[68] Fix | Delete
) {
[69] Fix | Delete
$cache = [];
[70] Fix | Delete
[71] Fix | Delete
return preg_replace_callback(
[72] Fix | Delete
'/{\s*([A-Za-z_\-\.0-9]+)\s*}/',
[73] Fix | Delete
function (array $matches) use ($request, $response, $error, &$cache) {
[74] Fix | Delete
if (isset($cache[$matches[1]])) {
[75] Fix | Delete
return $cache[$matches[1]];
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
$result = '';
[79] Fix | Delete
switch ($matches[1]) {
[80] Fix | Delete
case 'request':
[81] Fix | Delete
$result = Psr7\str($request);
[82] Fix | Delete
break;
[83] Fix | Delete
case 'response':
[84] Fix | Delete
$result = $response ? Psr7\str($response) : '';
[85] Fix | Delete
break;
[86] Fix | Delete
case 'req_headers':
[87] Fix | Delete
$result = trim($request->getMethod()
[88] Fix | Delete
. ' ' . $request->getRequestTarget())
[89] Fix | Delete
. ' HTTP/' . $request->getProtocolVersion() . "\r\n"
[90] Fix | Delete
. $this->headers($request);
[91] Fix | Delete
break;
[92] Fix | Delete
case 'res_headers':
[93] Fix | Delete
$result = $response ?
[94] Fix | Delete
sprintf(
[95] Fix | Delete
'HTTP/%s %d %s',
[96] Fix | Delete
$response->getProtocolVersion(),
[97] Fix | Delete
$response->getStatusCode(),
[98] Fix | Delete
$response->getReasonPhrase()
[99] Fix | Delete
) . "\r\n" . $this->headers($response)
[100] Fix | Delete
: 'NULL';
[101] Fix | Delete
break;
[102] Fix | Delete
case 'req_body':
[103] Fix | Delete
$result = $request->getBody();
[104] Fix | Delete
break;
[105] Fix | Delete
case 'res_body':
[106] Fix | Delete
$result = $response ? $response->getBody() : 'NULL';
[107] Fix | Delete
break;
[108] Fix | Delete
case 'ts':
[109] Fix | Delete
case 'date_iso_8601':
[110] Fix | Delete
$result = gmdate('c');
[111] Fix | Delete
break;
[112] Fix | Delete
case 'date_common_log':
[113] Fix | Delete
$result = date('d/M/Y:H:i:s O');
[114] Fix | Delete
break;
[115] Fix | Delete
case 'method':
[116] Fix | Delete
$result = $request->getMethod();
[117] Fix | Delete
break;
[118] Fix | Delete
case 'version':
[119] Fix | Delete
$result = $request->getProtocolVersion();
[120] Fix | Delete
break;
[121] Fix | Delete
case 'uri':
[122] Fix | Delete
case 'url':
[123] Fix | Delete
$result = $request->getUri();
[124] Fix | Delete
break;
[125] Fix | Delete
case 'target':
[126] Fix | Delete
$result = $request->getRequestTarget();
[127] Fix | Delete
break;
[128] Fix | Delete
case 'req_version':
[129] Fix | Delete
$result = $request->getProtocolVersion();
[130] Fix | Delete
break;
[131] Fix | Delete
case 'res_version':
[132] Fix | Delete
$result = $response
[133] Fix | Delete
? $response->getProtocolVersion()
[134] Fix | Delete
: 'NULL';
[135] Fix | Delete
break;
[136] Fix | Delete
case 'host':
[137] Fix | Delete
$result = $request->getHeaderLine('Host');
[138] Fix | Delete
break;
[139] Fix | Delete
case 'hostname':
[140] Fix | Delete
$result = gethostname();
[141] Fix | Delete
break;
[142] Fix | Delete
case 'code':
[143] Fix | Delete
$result = $response ? $response->getStatusCode() : 'NULL';
[144] Fix | Delete
break;
[145] Fix | Delete
case 'phrase':
[146] Fix | Delete
$result = $response ? $response->getReasonPhrase() : 'NULL';
[147] Fix | Delete
break;
[148] Fix | Delete
case 'error':
[149] Fix | Delete
$result = $error ? $error->getMessage() : 'NULL';
[150] Fix | Delete
break;
[151] Fix | Delete
default:
[152] Fix | Delete
// handle prefixed dynamic headers
[153] Fix | Delete
if (strpos($matches[1], 'req_header_') === 0) {
[154] Fix | Delete
$result = $request->getHeaderLine(substr($matches[1], 11));
[155] Fix | Delete
} elseif (strpos($matches[1], 'res_header_') === 0) {
[156] Fix | Delete
$result = $response
[157] Fix | Delete
? $response->getHeaderLine(substr($matches[1], 11))
[158] Fix | Delete
: 'NULL';
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
$cache[$matches[1]] = $result;
[163] Fix | Delete
return $result;
[164] Fix | Delete
},
[165] Fix | Delete
$this->template
[166] Fix | Delete
);
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Get headers from message as string
[171] Fix | Delete
*
[172] Fix | Delete
* @return string
[173] Fix | Delete
*/
[174] Fix | Delete
private function headers(MessageInterface $message)
[175] Fix | Delete
{
[176] Fix | Delete
$result = '';
[177] Fix | Delete
foreach ($message->getHeaders() as $name => $values) {
[178] Fix | Delete
$result .= $name . ': ' . implode(', ', $values) . "\r\n";
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
return trim($result);
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function