Skip to content

Commit

Permalink
Merge pull request #27 from dotkernel/issue-26
Browse files Browse the repository at this point in the history
Issue #26: Bumped PHP to 8.4
  • Loading branch information
arhimede authored Oct 22, 2024
2 parents 237fa82 + b47325a commit 598646f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignore_php_platform_requirements": {
"8.4": true
},
"backwardCompatibilityCheck": true
}
54 changes: 31 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -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:

<?php
```php
<?php
return [
'dot_response_headers' => [
'*' => [
Expand All @@ -63,25 +68,28 @@ 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.

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`.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"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"
},
"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"
Expand Down
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/book/index.md
4 changes: 2 additions & 2 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 1 addition & 10 deletions test/Middleware/ResponseHeaderMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
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
{
private ResponseHeaderMiddleware $responseHeader;

private ServerRequestInterface|MockObject $serverRequest;

private RequestHandlerInterface|MockObject $requestHandler;

/**
Expand All @@ -32,17 +29,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
Expand Down

0 comments on commit 598646f

Please sign in to comment.