Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/cs-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
- push

name: Run phpcs checks

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run phpcs checks
run: vendor/bin/phpcs
46 changes: 46 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
- push

name: Run static analysis

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4
47 changes: 47 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
- push

name: Run PHPUnit tests

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-

- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run PHPUnit tests
run: vendor/bin/phpunit --colors=always
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
composer.phar
/vendor/
.phpcs-cache
.idea
composer.lock
.phpunit.result.cache
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
* Nothing

### Fixed
* Nothing
* Nothing
11 changes: 8 additions & 3 deletions README.md
Comment thread
alexmerlin marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# 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.1.0)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-response-header/3.2.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)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-response-header)](https://github.com/dotkernel/dot-response-header/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-response-header)](https://github.com/dotkernel/response-header/LICENSE.md)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-response-header)](https://github.com/dotkernel/dot-response-header/blob/3.0/LICENSE)

[![Build Static](https://github.com/dotkernel/dot-response-header/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-response-header/actions/workflows/static-analysis.yml)

[![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
- PHP >= 7.4
- PHP >= 8.1

### Installation

Expand Down
37 changes: 32 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,42 @@
"mezzio"
],
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0"
"php": "~8.1.0 || ~8.2.0",
"mezzio/mezzio-router": "^3.16",
"psr/http-client": "^1.0",
"psr/http-message": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.20",
"squizlabs/php_codesniffer": "^3.6.2"
"laminas/laminas-coding-standard": "^2.5",
"laminas/laminas-diactoros": "^3.0",
"phpunit/phpunit": "^10.2",
"vimeo/psalm": "^5.13"
},
"autoload": {
"psr-4": {
"Dot\\ResponseHeader\\": "src"
"Dot\\ResponseHeader\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DotTest\\ResponseHeader\\": "test/"
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"static-analysis": "psalm --shepherd --stats"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
}
}
}
2 changes: 1 addition & 1 deletion config/response-header.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ return [
]
]
]
];
];
21 changes: 21 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>config</file>
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
14 changes: 14 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap="./vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="dot-response-header Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
<coverage/>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
17 changes: 17 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
findUnusedCode="false"
findUnusedBaselineEntry="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
13 changes: 2 additions & 11 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<?php

declare(strict_types=1);

namespace Dot\ResponseHeader;

use Dot\ResponseHeader\Factory\ResponseHeaderMiddlewareFactory;
use Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware;

/**
* Class ConfigProvider
* @package Dot\ResponseHeader
*/
class ConfigProvider
{
/**
* @return array
*/
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
];
}

/**
* @return array
*/
public function getDependencies(): array
{
return [
Expand All @@ -33,4 +24,4 @@ public function getDependencies(): array
],
];
}
}
}
34 changes: 27 additions & 7 deletions src/Factory/ResponseHeaderMiddlewareFactory.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
<?php

declare(strict_types=1);

namespace Dot\ResponseHeader\Factory;

use Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

use function array_key_exists;
use function is_array;

/**
* Class ResponseHeaderMiddlewareFactory
* @package Dot\ResponseHeader\Factory
*/
class ResponseHeaderMiddlewareFactory
{
public const MESSAGE_MISSING_CONFIG = 'Unable to find config.';
public const MESSAGE_MISSING_PACKAGE_CONFIG = 'Unable to find dot-response-header config.';

/**
* @param ContainerInterface $container
* @return ResponseHeaderMiddleware
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function __invoke(ContainerInterface $container): ResponseHeaderMiddleware
{
if (! $container->has('config')) {
throw new Exception(self::MESSAGE_MISSING_CONFIG);
}
$config = $container->get('config');

if (
! array_key_exists('dot_response_headers', $config)
|| ! is_array($config['dot_response_headers'])
|| empty($config['dot_response_headers'])
) {
throw new Exception(self::MESSAGE_MISSING_PACKAGE_CONFIG);
}

return new ResponseHeaderMiddleware($container->get('config')['dot_response_headers'] ?? []);
Comment thread
alexmerlin marked this conversation as resolved.
}
}
}
Loading