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 @@