diff --git a/src/CookieCollection.php b/src/CookieCollection.php
index aa2f102c9..910cac0a3 100644
--- a/src/CookieCollection.php
+++ b/src/CookieCollection.php
@@ -13,6 +13,8 @@
use IteratorAggregate;
use Psr\Http\Message\ResponseInterface;
+use Yiisoft\Http\Header;
+
use function array_keys;
use function array_values;
use function array_walk;
@@ -34,7 +36,7 @@ final class CookieCollection implements IteratorAggregate, ArrayAccess, Countabl
/**
* CookieCollection constructor.
*
- * @param array $cookies the cookies that this collection initially contains.
+ * @param Cookie[] $cookies the cookies that this collection initially contains.
*/
public function __construct(array $cookies = [])
{
@@ -339,7 +341,7 @@ public function addToResponse(ResponseInterface $response): ResponseInterface
*/
public function setToResponse(ResponseInterface $response): ResponseInterface
{
- $response = $response->withoutHeader('Set-Cookie');
+ $response = $response->withoutHeader(Header::SET_COOKIE);
return $this->addToResponse($response);
}
@@ -353,7 +355,7 @@ public function setToResponse(ResponseInterface $response): ResponseInterface
public static function fromResponse(ResponseInterface $response): self
{
$collection = new self();
- foreach ($response->getHeader('Set-Cookie') as $setCookieString) {
+ foreach ($response->getHeader(Header::SET_COOKIE) as $setCookieString) {
$cookie = Cookie::fromCookieString($setCookieString);
$collection->add($cookie);
}
diff --git a/src/Data/Formatter/HtmlDataResponseFormatter.php b/src/Data/Formatter/HtmlDataResponseFormatter.php
index 5028dd31c..99d000f67 100644
--- a/src/Data/Formatter/HtmlDataResponseFormatter.php
+++ b/src/Data/Formatter/HtmlDataResponseFormatter.php
@@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Web\Data\Formatter;
use Psr\Http\Message\ResponseInterface;
+use Yiisoft\Http\Header;
use Yiisoft\Yii\Web\Data\DataResponse;
use Yiisoft\Yii\Web\Data\DataResponseFormatterInterface;
@@ -26,7 +27,7 @@ public function format(DataResponse $dataResponse): ResponseInterface
$response = $dataResponse->getResponse();
$response->getBody()->write((string)$data);
- return $response->withHeader('Content-Type', $this->contentType . '; charset=' . $this->encoding);
+ return $response->withHeader(Header::CONTENT_TYPE, $this->contentType . '; charset=' . $this->encoding);
}
public function withEncoding(string $encoding): self
diff --git a/src/Data/Formatter/JsonDataResponseFormatter.php b/src/Data/Formatter/JsonDataResponseFormatter.php
index 82dfb2403..61be23eb9 100644
--- a/src/Data/Formatter/JsonDataResponseFormatter.php
+++ b/src/Data/Formatter/JsonDataResponseFormatter.php
@@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Web\Data\Formatter;
use Psr\Http\Message\ResponseInterface;
+use Yiisoft\Http\Header;
use Yiisoft\Serializer\JsonSerializer;
use Yiisoft\Yii\Web\Data\DataResponse;
use Yiisoft\Yii\Web\Data\DataResponseFormatterInterface;
@@ -25,7 +26,7 @@ public function format(DataResponse $dataResponse): ResponseInterface
$response = $dataResponse->getResponse();
$response->getBody()->write($content);
- return $response->withHeader('Content-Type', $this->contentType);
+ return $response->withHeader(Header::CONTENT_TYPE, $this->contentType);
}
public function withOptions(int $options): self
diff --git a/src/Data/Formatter/XmlDataResponseFormatter.php b/src/Data/Formatter/XmlDataResponseFormatter.php
index a40cf0130..17e27c699 100644
--- a/src/Data/Formatter/XmlDataResponseFormatter.php
+++ b/src/Data/Formatter/XmlDataResponseFormatter.php
@@ -9,6 +9,7 @@
use DOMException;
use DOMText;
use Psr\Http\Message\ResponseInterface;
+use Yiisoft\Http\Header;
use Yiisoft\Strings\StringHelper;
use Yiisoft\Yii\Web\Data\DataResponse;
use Yiisoft\Yii\Web\Data\DataResponseFormatterInterface;
@@ -63,7 +64,7 @@ public function format(DataResponse $dataResponse): ResponseInterface
$response = $dataResponse->getResponse();
$response->getBody()->write($content);
- return $response->withHeader('Content-Type', $this->contentType . '; ' . $this->encoding);
+ return $response->withHeader(Header::CONTENT_TYPE, $this->contentType . '; ' . $this->encoding);
}
public function withVersion(string $version): self
diff --git a/src/ErrorHandler/ErrorCatcher.php b/src/ErrorHandler/ErrorCatcher.php
index 4886d3777..ac1b6fb53 100644
--- a/src/ErrorHandler/ErrorCatcher.php
+++ b/src/ErrorHandler/ErrorCatcher.php
@@ -10,12 +10,13 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
+use Yiisoft\Http\Header;
use Yiisoft\Http\HeaderHelper;
use Yiisoft\Http\Status;
/**
* ErrorCatcher catches all throwables from the next middlewares and renders it
- * accoring to the content type passed by the client.
+ * according to the content type passed by the client.
*/
final class ErrorCatcher implements MiddlewareInterface
{
@@ -83,7 +84,7 @@ private function handleException(\Throwable $e, ServerRequestInterface $request)
}
$content = $this->errorHandler->handleCaughtThrowable($e, $renderer);
$response = $this->responseFactory->createResponse(Status::INTERNAL_SERVER_ERROR)
- ->withHeader('Content-type', $contentType);
+ ->withHeader(Header::CONTENT_TYPE, $contentType);
$response->getBody()->write($content);
return $response;
}
diff --git a/src/ErrorHandler/HtmlRenderer.php b/src/ErrorHandler/HtmlRenderer.php
index e98a6b5bc..06ef60399 100644
--- a/src/ErrorHandler/HtmlRenderer.php
+++ b/src/ErrorHandler/HtmlRenderer.php
@@ -19,12 +19,9 @@ final class HtmlRenderer extends ThrowableRenderer
private string $errorTemplate;
private string $exceptionTemplate;
- private array $defaultTemplates;
-
public function __construct(array $templates = [])
{
$this->defaultTemplatePath = $templates['path'];
- $this->defaultTemplates = $templates['default'];
$this->errorTemplate = $templates['error'] ?? $this->defaultTemplatePath . '/error.php';
$this->exceptionTemplate = $templates['exception'] ?? $this->defaultTemplatePath . '/exception.php';
}
diff --git a/src/ErrorHandler/XmlRenderer.php b/src/ErrorHandler/XmlRenderer.php
index b9be01ca6..770c9d098 100644
--- a/src/ErrorHandler/XmlRenderer.php
+++ b/src/ErrorHandler/XmlRenderer.php
@@ -24,9 +24,9 @@ public function renderVerbose(\Throwable $t): string
$out .= "\n";
$out .= $this->tag('type', get_class($t));
$out .= $this->tag('message', $this->cdata($t->getMessage()));
- $out .= $this->tag('code', $this->cdata($t->getCode()));
+ $out .= $this->tag('code', $this->cdata((string) $t->getCode()));
$out .= $this->tag('file', $t->getFile());
- $out .= $this->tag('line', $t->getLine());
+ $out .= $this->tag('line', (string) $t->getLine());
$out .= $this->tag('trace', $t->getTraceAsString());
$out .= '';
return $out;
diff --git a/src/ErrorHandler/templates/error.php b/src/ErrorHandler/templates/error.php
index ede0d0bf8..94b2fdee5 100644
--- a/src/ErrorHandler/templates/error.php
+++ b/src/ErrorHandler/templates/error.php
@@ -13,7 +13,7 @@
}
?>
-
+
= $this->htmlEncode($name) ?>
diff --git a/src/ErrorHandler/templates/exception.php b/src/ErrorHandler/templates/exception.php
index 0aefd87ca..75bd4719d 100644
--- a/src/ErrorHandler/templates/exception.php
+++ b/src/ErrorHandler/templates/exception.php
@@ -17,7 +17,6 @@
margin: 0;
padding: 0;
border: 0;
- font-size: 100%;
font: inherit;
vertical-align: baseline;
}
diff --git a/src/ErrorHandler/templates/previousException.php b/src/ErrorHandler/templates/previousException.php
index c8a6008d0..f566ca850 100644
--- a/src/ErrorHandler/templates/previousException.php
+++ b/src/ErrorHandler/templates/previousException.php
@@ -1,4 +1,5 @@
diff --git a/src/Middleware/ForceSecureConnection.php b/src/Middleware/ForceSecureConnection.php
index 904d00246..76bcabaa8 100644
--- a/src/Middleware/ForceSecureConnection.php
+++ b/src/Middleware/ForceSecureConnection.php
@@ -46,6 +46,7 @@ public function __construct(ResponseFactoryInterface $responseFactory)
{
$this->responseFactory = $responseFactory;
}
+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->redirect && strcasecmp($request->getUri()->getScheme(), 'http') === 0) {
diff --git a/src/Middleware/HttpCache.php b/src/Middleware/HttpCache.php
index b27bead69..244f85a58 100644
--- a/src/Middleware/HttpCache.php
+++ b/src/Middleware/HttpCache.php
@@ -4,11 +4,11 @@
namespace Yiisoft\Yii\Web\Middleware;
-use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
+use Yiisoft\Http\Header;
use Yiisoft\Http\Method;
use Yiisoft\Http\Status;
@@ -68,13 +68,6 @@ final class HttpCache implements MiddlewareInterface
*/
private ?string $cacheControlHeader = self::DEFAULT_HEADER;
- private ResponseFactoryInterface $responseFactory;
-
- public function __construct(ResponseFactoryInterface $responseFactory)
- {
- $this->responseFactory = $responseFactory;
- }
-
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (
@@ -105,16 +98,16 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
if ($this->cacheControlHeader !== null) {
- $response = $response->withHeader('Cache-Control', $this->cacheControlHeader);
+ $response = $response->withHeader(Header::CACHE_CONTROL, $this->cacheControlHeader);
}
if ($etag !== null) {
- $response = $response->withHeader('Etag', $etag);
+ $response = $response->withHeader(Header::ETAG, $etag);
}
// https://tools.ietf.org/html/rfc7232#section-4.1
- if ($lastModified !== null && (!$cacheIsValid || ($cacheIsValid && $etag === null))) {
+ if ($lastModified !== null && (!$cacheIsValid || $etag === null)) {
$response = $response->withHeader(
- 'Last-Modified',
+ Header::LAST_MODIFIED,
gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'
);
}
@@ -133,14 +126,14 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
*/
private function validateCache(ServerRequestInterface $request, ?int $lastModified, ?string $etag): bool
{
- if ($request->hasHeader('If-None-Match')) {
+ if ($request->hasHeader(Header::IF_NONE_MATCH)) {
// HTTP_IF_NONE_MATCH takes precedence over HTTP_IF_MODIFIED_SINCE
// http://tools.ietf.org/html/rfc7232#section-3.3
return $etag !== null && \in_array($etag, $this->getETags($request), true);
}
- if ($request->hasHeader('If-Modified-Since')) {
- $header = $request->getHeaderLine('If-Modified-Since');
+ if ($request->hasHeader(Header::IF_MODIFIED_SINCE)) {
+ $header = $request->getHeaderLine(Header::IF_MODIFIED_SINCE);
return $lastModified !== null && @strtotime($header) >= $lastModified;
}
@@ -166,8 +159,8 @@ private function generateEtag(string $seed): string
*/
private function getETags(ServerRequestInterface $request): array
{
- if ($request->hasHeader('If-None-Match')) {
- $header = $request->getHeaderLine('If-None-Match');
+ if ($request->hasHeader(Header::IF_NONE_MATCH)) {
+ $header = $request->getHeaderLine(Header::IF_NONE_MATCH);
$header = \str_replace('-gzip', '', $header);
return \preg_split('/[\s,]+/', $header, -1, PREG_SPLIT_NO_EMPTY) ?: [];
}
diff --git a/src/Middleware/TrustedHostsNetworkResolver.php b/src/Middleware/TrustedHostsNetworkResolver.php
index 4a1def917..32eb03b68 100644
--- a/src/Middleware/TrustedHostsNetworkResolver.php
+++ b/src/Middleware/TrustedHostsNetworkResolver.php
@@ -5,7 +5,6 @@
namespace Yiisoft\Yii\Web\Middleware;
use Psr\Http\Message\RequestInterface;
-use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
@@ -70,15 +69,8 @@ final class TrustedHostsNetworkResolver implements MiddlewareInterface
private ?string $attributeIps = null;
- private ResponseFactoryInterface $responseFactory;
-
private ?Ip $ipValidator = null;
- public function __construct(ResponseFactoryInterface $responseFactory)
- {
- $this->responseFactory = $responseFactory;
- }
-
public function withIpValidator(Ip $ipValidator): self
{
$new = clone $this;
diff --git a/src/NotFoundHandler.php b/src/NotFoundHandler.php
index 4ffd7dbab..ef92820e7 100644
--- a/src/NotFoundHandler.php
+++ b/src/NotFoundHandler.php
@@ -15,7 +15,7 @@ final class NotFoundHandler implements RequestHandlerInterface
/**
* @var ResponseFactoryInterface
*/
- private $responseFactory;
+ private ResponseFactoryInterface $responseFactory;
/**
* NotFoundHandler constructor.
diff --git a/src/ServerRequestFactory.php b/src/ServerRequestFactory.php
index 3e9df1f0c..1772608d6 100644
--- a/src/ServerRequestFactory.php
+++ b/src/ServerRequestFactory.php
@@ -107,7 +107,7 @@ private function getUri(array $server): UriInterface
}
if (isset($server['HTTP_HOST'])) {
- if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) {
+ if (1 === \preg_match('/^(.+):(\d+)$/', $server['HTTP_HOST'], $matches)) {
$uri = $uri->withHost($matches[1])->withPort($matches[2]);
} else {
$uri = $uri->withHost($server['HTTP_HOST']);
diff --git a/src/Session/SessionInterface.php b/src/Session/SessionInterface.php
index 848a77dd4..73f7374de 100644
--- a/src/Session/SessionInterface.php
+++ b/src/Session/SessionInterface.php
@@ -29,7 +29,7 @@ public function set(string $key, $value): void;
public function close(): void;
/**
- * Start sesion if it is not started yet
+ * Start session if it is not started yet
*/
public function open(): void;
diff --git a/src/Session/SessionMiddleware.php b/src/Session/SessionMiddleware.php
index c7d365b57..8ed1a37a9 100644
--- a/src/Session/SessionMiddleware.php
+++ b/src/Session/SessionMiddleware.php
@@ -46,7 +46,7 @@ private function commitSession(ServerRequestInterface $request, ResponseInterfac
$currentSid = $this->session->getID();
- // SID changed, neeed to send new cookie
+ // SID changed, need to send new cookie
if ($this->getSidFromRequest($request) !== $currentSid) {
$cookieParameters = $this->session->getCookieParameters();
diff --git a/src/User/User.php b/src/User/User.php
index 88e7ebc4d..694e68e5d 100644
--- a/src/User/User.php
+++ b/src/User/User.php
@@ -20,6 +20,19 @@ class User
private const SESSION_AUTH_EXPIRE = '__auth_expire';
private const SESSION_AUTH_ABSOLUTE_EXPIRE = '__auth_absolute_expire';
+ /**
+ * @var int|null the number of seconds in which the user will be logged out automatically in case of
+ * remaining inactive. If this property is not set, the user will be logged out after
+ * the current session expires.
+ */
+ public ?int $authTimeout = null;
+
+ /**
+ * @var int|null the number of seconds in which the user will be logged out automatically
+ * regardless of activity.
+ */
+ public ?int $absoluteAuthTimeout = null;
+
private IdentityRepositoryInterface $identityRepository;
private EventDispatcherInterface $eventDispatcher;
@@ -44,19 +57,6 @@ public function __construct(
$this->session = $session;
}
- /**
- * @var int|null the number of seconds in which the user will be logged out automatically if he
- * remains inactive. If this property is not set, the user will be logged out after
- * the current session expires.
- */
- public ?int $authTimeout = null;
-
- /**
- * @var int|null the number of seconds in which the user will be logged out automatically
- * regardless of activity.
- */
- public ?int $absoluteAuthTimeout = null;
-
public function setAccessChecker(AccessCheckerInterface $accessChecker): void
{
$this->accessChecker = $accessChecker;
@@ -72,7 +72,7 @@ public function setAccessChecker(AccessCheckerInterface $accessChecker): void
* @see logout()
* @see login()
*/
- public function getIdentity($autoRenew = true): IdentityInterface
+ public function getIdentity(bool $autoRenew = true): IdentityInterface
{
if ($this->identity !== null) {
return $this->identity;
@@ -151,7 +151,7 @@ public function loginByAccessToken(string $token, string $type = null): ?Identit
* @return bool whether the user is logged out
* @throws \Throwable
*/
- public function logout($destroySession = true): bool
+ public function logout(bool $destroySession = true): bool
{
$identity = $this->getIdentity();
if ($this->isGuest()) {