This commit is contained in:
2026-02-26 14:39:05 +08:00
parent d098b293a4
commit a2138bdd3b
5 changed files with 1407 additions and 1419 deletions
+11
View File
@@ -20,6 +20,17 @@ interface AuthorizationInterface
public function getUniqueId(): string|int; public function getUniqueId(): string|int;
/**
* @return string
*/
public function getNickname(): string;
/**
* @return string
*/
public function getAvatar(): string;
/** /**
* @param string $key * @param string $key
+10 -1
View File
@@ -85,6 +85,15 @@ class ConstrictRequest extends Message implements RequestInterface, ServerReques
} }
/**
* @return array
*/
public function getCookieParams(): array
{
return $this->cookieParams;
}
/** /**
* Retrieves the message's request target. * Retrieves the message's request target.
* *
@@ -568,7 +577,7 @@ class ConstrictRequest extends Message implements RequestInterface, ServerReques
*/ */
public static function builder(Request $request): static public static function builder(Request $request): static
{ {
$static = (new static())->withUri(new Uri($request)); $static = (new static)->withUri(new Uri($request));
$static->withHeaders($request->header ?? []); $static->withHeaders($request->header ?? []);
$static->withProtocolVersion($request->server['server_protocol']); $static->withProtocolVersion($request->server['server_protocol']);
$static->withCookieParams($request->cookie ?? []); $static->withCookieParams($request->cookie ?? []);
+7 -49
View File
@@ -31,7 +31,13 @@ class Message extends Component implements MessageInterface
/** /**
* @var array * @var array
*/ */
private array $cookieParams = []; public array $cookieParams = [];
/**
* @var array
*/
public array $data = [];
/** /**
@@ -45,23 +51,6 @@ class Message extends Component implements MessageInterface
} }
/**
* Retrieve cookies.
*
* Retrieves cookies sent by the client to the server.
*
* The data MUST be compatible with the structure of the $_COOKIE
* superglobal.
*
* @return array
*/
public function getCookieParams(): array
{
// TODO: Implement getCookieParams() method.
return $this->cookieParams;
}
/** /**
* Return an instance with the specified cookies. * Return an instance with the specified cookies.
* *
@@ -120,37 +109,6 @@ class Message extends Component implements MessageInterface
return $this; return $this;
} }
/**
* Retrieves all message header values.
*
* The keys represent the header name as it will be sent over the wire, and
* each value is an array of strings associated with the header.
*
* // Represent the headers as a string
* foreach ($message->getHeaders() as $name => $values) {
* echo $name . ": " . implode(", ", $values);
* }
*
* // Emit headers iteratively:
* foreach ($message->getHeaders() as $name => $values) {
* foreach ($values as $value) {
* header(sprintf('%s: %s', $name, $value), false);
* }
* }
*
* While header names are not case-sensitive, getHeaders() will preserve the
* exact case in which headers were originally specified.
*
* @return string[][] Returns an associative array of the message's headers. Each
* key MUST be a header name, and each value MUST be an array of strings
* for that header.
*/
public function getHeaders(): array
{
// TODO: Implement getHeaders() method.
return $this->headers;
}
/** /**
* Checks if a header exists by the given case-insensitive name. * Checks if a header exists by the given case-insensitive name.
* *
+10
View File
@@ -813,6 +813,16 @@ class Request implements ServerRequestInterface
} }
/**
* @param string $name
* @return bool
*/
public function hasQuery(string $name): bool
{
return $this->getQueryParams()[$name] ?? false;
}
/** /**
* @param string $name * @param string $name
* @param mixed|null $value * @param mixed|null $value
+1 -1
View File
@@ -98,7 +98,7 @@ class Session
*/ */
private static function getSessionId(ServerRequestInterface $request): string private static function getSessionId(ServerRequestInterface $request): string
{ {
$cookies = $request->getCookieParams(); $cookies = $request->cookieParams;
// 从 Cookie 中获取 Session ID // 从 Cookie 中获取 Session ID
if (isset($cookies[self::SESSION_NAME]) && !empty($cookies[self::SESSION_NAME])) { if (isset($cookies[self::SESSION_NAME]) && !empty($cookies[self::SESSION_NAME])) {