From 067ebe8044aec235f5da8111a070fb347c02011b Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 08:21:35 +0300 Subject: [PATCH 1/6] Issue #26: Bumped PHP to 8.4 Signed-off-by: alexmerlin --- README.md | 54 ++++++++++++++++++++++++++-------------------- composer.json | 2 +- docs/book/index.md | 2 +- 3 files changed, 33 insertions(+), 25 deletions(-) mode change 100644 => 120000 docs/book/index.md diff --git a/README.md b/README.md index ca61a51..d18cbeb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # dot-response-header ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-response-header) -![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-response-header/3.2.3) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-response-header/3.4.0) [![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-response-header)](https://github.com/dotkernel/dot-response-header/issues) [![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-response-header)](https://github.com/dotkernel/dot-response-header/network) @@ -11,8 +11,6 @@ [![Build Static](https://github.com/dotkernel/dot-response-header/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-response-header/actions/workflows/continuous-integration.yml) [![codecov](https://codecov.io/gh/dotkernel/dot-response-header/graph/badge.svg?token=NNRZN0FBF2)](https://codecov.io/gh/dotkernel/dot-response-header) -[![SymfonyInsight](https://insight.symfony.com/projects/dce88959-bd29-40ef-b1e7-d12815145438/big.svg)](https://insight.symfony.com/projects/dce88959-bd29-40ef-b1e7-d12815145438) - Middleware for setting and overwriting custom response headers. ## Requirements @@ -23,22 +21,29 @@ Middleware for setting and overwriting custom response headers. Run the following command in your project root directory - composer require dotkernel/dot-response-header +```shell +composer require dotkernel/dot-response-header +``` Next, register the package's `ConfigProvider` to your application config. - Dot\ResponseHeader\ConfigProvider::class, +```php +Dot\ResponseHeader\ConfigProvider::class, +``` -Note : Make sure to register the package under the `// DK packages` section. +Note: Make sure to register the package under the `// DK packages` section. After registering the package, add it to the middleware stack in `config/pipeline.php` after `$app->pipe(RouteMiddleware::class);` - $app->pipe(RouteMiddleware::class); - $app->pipe(\Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware::class); +```php +$app->pipe(RouteMiddleware::class); +$app->pipe(\Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware::class); +``` -Create a new file `response-header.global.php` in `config/autoload` with the below configuration array : +Create a new file `response-header.global.php` in `config/autoload` with the below configuration array: - [ '*' => [ @@ -63,7 +68,8 @@ Create a new file `response-header.global.php` in `config/autoload` with the bel ] ], ] - ]; + ]; +``` Because headers are matched with route names, we can have custom response headers for every request, by defining new headers under the `*` key. @@ -71,17 +77,19 @@ All headers under `*` will be set for every response. To add response headers for a specific set of routes, define a new array using the route name as the array key. -Example : - - 'dot_response_headers' => [ - 'user' => [ - 'UserCustomHeader' => [ - 'value' => 'UserCustomHeader-Value', - 'overwrite' => false - ] - ], - ] - - // This will set a new header named UserCustomHeader with the UserCustomHeader-Value value for any route name matching 'user' +Example: + +```php +'dot_response_headers' => [ + 'user' => [ + 'UserCustomHeader' => [ + 'value' => 'UserCustomHeader-Value', + 'overwrite' => false + ] + ], +] + +// This will set a new header named UserCustomHeader with the UserCustomHeader-Value value for any route name matching 'user' +``` To overwrite an existing header use `overwrite => true`. diff --git a/composer.json b/composer.json index 5d109d8..d657b16 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "mezzio" ], "require": { - "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", "mezzio/mezzio-router": "^3.16", "psr/http-client": "^1.0", "psr/http-message": "^1.0 || ^2.0" diff --git a/docs/book/index.md b/docs/book/index.md deleted file mode 100644 index ae42a26..0000000 --- a/docs/book/index.md +++ /dev/null @@ -1 +0,0 @@ -../../README.md diff --git a/docs/book/index.md b/docs/book/index.md new file mode 120000 index 0000000..fe84005 --- /dev/null +++ b/docs/book/index.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file From 2eb6d31e85c32353c27e42f868f575a1af3a8baa Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 08:52:14 +0300 Subject: [PATCH 2/6] Fixed tests Signed-off-by: alexmerlin --- .laminas-ci.json | 6 ++++++ test/ConfigProviderTest.php | 4 ++-- test/Middleware/ResponseHeaderMiddlewareTest.php | 10 +--------- 3 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 .laminas-ci.json diff --git a/.laminas-ci.json b/.laminas-ci.json new file mode 100644 index 0000000..82cd446 --- /dev/null +++ b/.laminas-ci.json @@ -0,0 +1,6 @@ +{ + "ignore_php_platform_requirements": { + "8.4": true + }, + "backwardCompatibilityCheck": true +} diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 23a3255..c0d57d4 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -16,14 +16,14 @@ public function setUp(): void $this->configProvider = new ConfigProvider(); } - public function testInvoke() + public function testInvoke(): void { $data = $this->configProvider->__invoke(); $this->assertIsArray($data); } - public function testGetDependencies() + public function testGetDependencies(): void { $data = $this->configProvider->getDependencies(); diff --git a/test/Middleware/ResponseHeaderMiddlewareTest.php b/test/Middleware/ResponseHeaderMiddlewareTest.php index 5e929bb..bb34eca 100644 --- a/test/Middleware/ResponseHeaderMiddlewareTest.php +++ b/test/Middleware/ResponseHeaderMiddlewareTest.php @@ -17,9 +17,7 @@ class ResponseHeaderMiddlewareTest extends TestCase { private ResponseHeaderMiddleware $responseHeader; - private ServerRequestInterface|MockObject $serverRequest; - private RequestHandlerInterface|MockObject $requestHandler; /** @@ -32,17 +30,11 @@ public function setUp(): void $this->requestHandler = $this->createMock(RequestHandlerInterface::class); } - public function testProcess() + public function testProcess(): void { $data = $this->responseHeader->process($this->serverRequest, $this->requestHandler); $this->assertInstanceOf(ResponseInterface::class, $data); - $this->assertInstanceOf(StreamInterface::class, $data->getBody()); - $this->assertNotEmpty($data->getBody()); - $this->assertIsArray($data->getHeaders()); - $this->assertIsInt($data->getStatusCode()); - $this->assertIsString($data->getProtocolVersion()); - $this->assertIsString($data->getReasonPhrase()); } public function testWillNotAddHeadersWithoutCommonWithoutRouteSpecificHeadersConfigured(): void From 291d8fe4263f95758f30e92cc10ef9c6e9a5d01d Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 08:54:21 +0300 Subject: [PATCH 3/6] Removed unnecessary use Signed-off-by: alexmerlin --- test/Middleware/ResponseHeaderMiddlewareTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Middleware/ResponseHeaderMiddlewareTest.php b/test/Middleware/ResponseHeaderMiddlewareTest.php index bb34eca..75bc016 100644 --- a/test/Middleware/ResponseHeaderMiddlewareTest.php +++ b/test/Middleware/ResponseHeaderMiddlewareTest.php @@ -11,7 +11,6 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\StreamInterface; use Psr\Http\Server\RequestHandlerInterface; class ResponseHeaderMiddlewareTest extends TestCase From f9ac9c6e36be6fa8fa0ccf9789e0e76543f71cee Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 08:55:52 +0300 Subject: [PATCH 4/6] Added PHP 8.4 to codecov Signed-off-by: alexmerlin --- .github/workflows/codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 190b4da..7ad749b 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -18,6 +18,7 @@ jobs: - "8.1" - "8.2" - "8.3" + - "8.4" steps: - name: Checkout From 5de6cf45ddb0e45b262bdb72910632a2c6e62222 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 09:02:41 +0300 Subject: [PATCH 5/6] Removed PHP 8.4 from codecov Signed-off-by: alexmerlin --- .github/workflows/codecov.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 7ad749b..190b4da 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -18,7 +18,6 @@ jobs: - "8.1" - "8.2" - "8.3" - - "8.4" steps: - name: Checkout From b47325a55173ed8f2d2a5f99d86e0677b6a93e1d Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 12:55:48 +0300 Subject: [PATCH 6/6] Bump laminas-coding-standard to 3.x Signed-off-by: alexmerlin --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d657b16..21c59e0 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "psr/http-message": "^1.0 || ^2.0" }, "require-dev": { - "laminas/laminas-coding-standard": "^2.5", + "laminas/laminas-coding-standard": "^3.0", "laminas/laminas-diactoros": "^3.1", "phpunit/phpunit": "^10.2", "vimeo/psalm": "^5.13"