处理 vendor 依赖错误问题

This commit is contained in:
柳清爽
2025-03-25 18:31:48 +08:00
parent f7f48a03fe
commit 4af129acf8
416 changed files with 26268 additions and 28381 deletions

View File

@@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
namespace GuzzleHttp\Psr7;
use Psr\Http\Message\MessageInterface;
@@ -14,35 +12,37 @@ final class Message
* Returns the string representation of an HTTP message.
*
* @param MessageInterface $message Message to convert to a string.
*
* @return string
*/
public static function toString(MessageInterface $message): string
public static function toString(MessageInterface $message)
{
if ($message instanceof RequestInterface) {
$msg = trim($message->getMethod().' '
.$message->getRequestTarget())
.' HTTP/'.$message->getProtocolVersion();
$msg = trim($message->getMethod() . ' '
. $message->getRequestTarget())
. ' HTTP/' . $message->getProtocolVersion();
if (!$message->hasHeader('host')) {
$msg .= "\r\nHost: ".$message->getUri()->getHost();
$msg .= "\r\nHost: " . $message->getUri()->getHost();
}
} elseif ($message instanceof ResponseInterface) {
$msg = 'HTTP/'.$message->getProtocolVersion().' '
.$message->getStatusCode().' '
.$message->getReasonPhrase();
$msg = 'HTTP/' . $message->getProtocolVersion() . ' '
. $message->getStatusCode() . ' '
. $message->getReasonPhrase();
} else {
throw new \InvalidArgumentException('Unknown message type');
}
foreach ($message->getHeaders() as $name => $values) {
if (is_string($name) && strtolower($name) === 'set-cookie') {
if (strtolower($name) === 'set-cookie') {
foreach ($values as $value) {
$msg .= "\r\n{$name}: ".$value;
$msg .= "\r\n{$name}: " . $value;
}
} else {
$msg .= "\r\n{$name}: ".implode(', ', $values);
$msg .= "\r\n{$name}: " . implode(', ', $values);
}
}
return "{$msg}\r\n\r\n".$message->getBody();
return "{$msg}\r\n\r\n" . $message->getBody();
}
/**
@@ -52,8 +52,10 @@ final class Message
*
* @param MessageInterface $message The message to get the body summary
* @param int $truncateAt The maximum allowed size of the summary
*
* @return string|null
*/
public static function bodySummary(MessageInterface $message, int $truncateAt = 120): ?string
public static function bodySummary(MessageInterface $message, $truncateAt = 120)
{
$body = $message->getBody();
@@ -67,7 +69,6 @@ final class Message
return null;
}
$body->rewind();
$summary = $body->read($truncateAt);
$body->rewind();
@@ -77,7 +78,7 @@ final class Message
// Matches any printable character, including unicode characters:
// letters, marks, numbers, punctuation, spacing, and separators.
if (preg_match('/[^\pL\pM\pN\pP\pS\pZ\n\r\t]/u', $summary) !== 0) {
if (preg_match('/[^\pL\pM\pN\pP\pS\pZ\n\r\t]/u', $summary)) {
return null;
}
@@ -94,7 +95,7 @@ final class Message
*
* @throws \RuntimeException
*/
public static function rewindBody(MessageInterface $message): void
public static function rewindBody(MessageInterface $message)
{
$body = $message->getBody();
@@ -111,8 +112,10 @@ final class Message
* array values, and a "body" key containing the body of the message.
*
* @param string $message HTTP request or response to parse.
*
* @return array
*/
public static function parseMessage(string $message): array
public static function parseMessage($message)
{
if (!$message) {
throw new \InvalidArgumentException('Invalid message');
@@ -126,7 +129,7 @@ final class Message
throw new \InvalidArgumentException('Invalid message: Missing header delimiter');
}
[$rawHeaders, $body] = $messageParts;
list($rawHeaders, $body) = $messageParts;
$rawHeaders .= "\r\n"; // Put back the delimiter we split previously
$headerParts = preg_split("/\r?\n/", $rawHeaders, 2);
@@ -134,7 +137,7 @@ final class Message
throw new \InvalidArgumentException('Invalid message: Missing status line');
}
[$startLine, $rawHeaders] = $headerParts;
list($startLine, $rawHeaders) = $headerParts;
if (preg_match("/(?:^HTTP\/|^[A-Z]+ \S+ HTTP\/)(\d+(?:\.\d+)?)/i", $startLine, $matches) && $matches[1] === '1.0') {
// Header folding is deprecated for HTTP/1.1, but allowed in HTTP/1.0
@@ -146,7 +149,7 @@ final class Message
// If these aren't the same, then one line didn't match and there's an invalid header.
if ($count !== substr_count($rawHeaders, "\n")) {
// Folding is deprecated, see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.4
// Folding is deprecated, see https://tools.ietf.org/html/rfc7230#section-3.2.4
if (preg_match(Rfc7230::HEADER_FOLD_REGEX, $rawHeaders)) {
throw new \InvalidArgumentException('Invalid header syntax: Obsolete line folding');
}
@@ -172,13 +175,12 @@ final class Message
*
* @param string $path Path from the start-line
* @param array $headers Array of headers (each value an array).
*
* @return string
*/
public static function parseRequestUri(string $path, array $headers): string
public static function parseRequestUri($path, array $headers)
{
$hostKey = array_filter(array_keys($headers), function ($k) {
// Numeric array keys are converted to int by PHP.
$k = (string) $k;
return strtolower($k) === 'host';
});
@@ -190,15 +192,17 @@ final class Message
$host = $headers[reset($hostKey)][0];
$scheme = substr($host, -4) === ':443' ? 'https' : 'http';
return $scheme.'://'.$host.'/'.ltrim($path, '/');
return $scheme . '://' . $host . '/' . ltrim($path, '/');
}
/**
* Parses a request message string into a request object.
*
* @param string $message Request message string.
*
* @return Request
*/
public static function parseRequest(string $message): RequestInterface
public static function parseRequest($message)
{
$data = self::parseMessage($message);
$matches = [];
@@ -223,15 +227,17 @@ final class Message
* Parses a response message string into a response object.
*
* @param string $message Response message string.
*
* @return Response
*/
public static function parseResponse(string $message): ResponseInterface
public static function parseResponse($message)
{
$data = self::parseMessage($message);
// According to https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2
// the space between status-code and reason-phrase is required. But
// browsers accept responses without space and reason as well.
// According to https://tools.ietf.org/html/rfc7230#section-3.1.2 the space
// between status-code and reason-phrase is required. But browsers accept
// responses without space and reason as well.
if (!preg_match('/^HTTP\/.* [0-9]{3}( .*|$)/', $data['start-line'])) {
throw new \InvalidArgumentException('Invalid response string: '.$data['start-line']);
throw new \InvalidArgumentException('Invalid response string: ' . $data['start-line']);
}
$parts = explode(' ', $data['start-line'], 3);
@@ -240,7 +246,7 @@ final class Message
$data['headers'],
$data['body'],
explode('/', $parts[0])[1],
$parts[2] ?? null
isset($parts[2]) ? $parts[2] : null
);
}
}