diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..26c5802 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,11 @@ +name: "Continuous Integration" + +on: + pull_request: + push: + branches: + tags: + +jobs: + ci: + uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x diff --git a/.github/workflows/cs-tests.yml b/.github/workflows/cs-tests.yml deleted file mode 100644 index e8bbade..0000000 --- a/.github/workflows/cs-tests.yml +++ /dev/null @@ -1,47 +0,0 @@ -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" - - "8.3" - - 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 phpcs checks - run: vendor/bin/phpcs diff --git a/.github/workflows/docs-build.yml b/.github/workflows/docs-build.yml new file mode 100644 index 0000000..1a7aa24 --- /dev/null +++ b/.github/workflows/docs-build.yml @@ -0,0 +1,16 @@ +name: docs-build + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + build-deploy: + runs-on: ubuntu-latest + steps: + - name: Build Docs + uses: dotkernel/documentation-theme/github-actions/docs@main + env: + DEPLOY_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index 6f7452d..0000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,47 +0,0 @@ -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" - - "8.3" - - 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 static analysis - run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index 7f5f333..0000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,48 +0,0 @@ -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" - - "8.3" - - 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 diff --git a/README.md b/README.md index 5d0c509..ca61a51 100644 --- a/README.md +++ b/README.md @@ -8,87 +8,80 @@ [![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/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) +[![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 -### Requirements - PHP >= 8.1 -### Installation +## Installation Run the following command in your project root directory composer require dotkernel/dot-response-header - Next, register the package's `ConfigProvider` to your application config. Dot\ResponseHeader\ConfigProvider::class, - 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);` +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); - -Create a new file ``response-header.global.php`` in ``config/autoload`` with the below configuration array : - -``` - [ - '*' => [ - 'CustomHeader1' => [ - 'value' => 'CustomHeader1-Value', - 'overwrite' => true, +Create a new file `response-header.global.php` in `config/autoload` with the below configuration array : + + [ + '*' => [ + 'CustomHeader1' => [ + 'value' => 'CustomHeader1-Value', + 'overwrite' => true, + ], + 'CustomHeader2' => [ + 'value' => 'CustomHeader2-Value', + 'overwrite' => false, + ], ], - 'CustomHeader2' => [ - 'value' => 'CustomHeader2-Value', - 'overwrite' => false, + 'home' => [ + 'CustomHeader' => [ + 'value' => 'header3', + ] ], - ], - 'home' => [ - 'CustomHeader' => [ - 'value' => 'header3', - ] - ], - 'login' => [ - 'LoginHeader' => [ - 'value' => 'LoginHeader-Value', - 'overwrite' => false - ] - ], - ] -]; -``` + 'login' => [ + 'LoginHeader' => [ + 'value' => 'LoginHeader-Value', + 'overwrite' => false + ] + ], + ] + ]; -Because headers are matched with route names, we can have custom response headers for every request, by defining new headers under the ``*`` key. +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. +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 - ] - ], -] +Example : -// This will set a new header named UserCustomHeader with the UserCustomHeader-Value value for any route name matching 'user' -``` + '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``. +To overwrite an existing header use `overwrite => true`. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..45e86c9 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,41 @@ +# Security Policy + +## Supported Versions + + +| Version | Supported | PHP Version | +|---------|--------------------|---------------------------------------------------------------------------------------------------------------------| +| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-response-header/3.2.3) | +| <= 2.x | :x: | | + + + + +## Reporting Potential Security Issues + +If you have encountered a potential security vulnerability in this project, +please report it to us at . We will work with you to +verify the vulnerability and patch it. + +When reporting issues, please provide the following information: + +- Component(s) affected +- A description indicating how to reproduce the issue +- A summary of the security vulnerability and impact + +We request that you contact us via the email address above and give the +project contributors a chance to resolve the vulnerability and issue a new +release prior to any public exposure; this helps protect the project's +users, and provides them with a chance to upgrade and/or update in order to +protect their applications. + + +## Policy + +If we verify a reported security vulnerability, our policy is: + +- We will patch the current release branch, as well as the immediate prior minor + release branch. + +- After patching the release branches, we will immediately issue new security + fix releases for each patched release branch. diff --git a/composer.json b/composer.json index 5d109d8..86d10dc 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "mezzio/mezzio-router": "^3.16", "psr/http-client": "^1.0", - "psr/http-message": "^1.0 || ^2.0" + "psr/http-message": "^2.0" }, "require-dev": { "laminas/laminas-coding-standard": "^2.5", diff --git a/docs/book/index.md b/docs/book/index.md new file mode 100644 index 0000000..ae42a26 --- /dev/null +++ b/docs/book/index.md @@ -0,0 +1 @@ +../../README.md diff --git a/docs/book/v3/configuration.md b/docs/book/v3/configuration.md new file mode 100644 index 0000000..64c3e9c --- /dev/null +++ b/docs/book/v3/configuration.md @@ -0,0 +1,57 @@ +# Configuration + +## Requirements + +- PHP >= 8.1 + +## Register ConfigProvider + +Next, register the package's `ConfigProvider` to your application config. + +```php +Dot\ResponseHeader\ConfigProvider::class, +``` + +Note : Make sure to register the package under the `// DK packages` section. + +## Add the package to the middleware stack + +After registering the package, add it to the middleware stack in `config/pipeline.php` after `$app->pipe(RouteMiddleware::class);` + +```php +$app->pipe(RouteMiddleware::class); +$app->pipe(\Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware::class); +``` + +## Add configuration in autoload + +Create a new file `response-header.global.php` in `config/autoload` with the below configuration array : + +```php + [ + '*' => [ + 'CustomHeader1' => [ + 'value' => 'CustomHeader1-Value', + 'overwrite' => true, + ], + 'CustomHeader2' => [ + 'value' => 'CustomHeader2-Value', + 'overwrite' => false, + ], + ], + 'home' => [ + 'CustomHeader' => [ + 'value' => 'header3', + ] + ], + 'login' => [ + 'LoginHeader' => [ + 'value' => 'LoginHeader-Value', + 'overwrite' => false + ] + ], + ] +]; +``` diff --git a/docs/book/v3/installation.md b/docs/book/v3/installation.md new file mode 100644 index 0000000..a1a5edb --- /dev/null +++ b/docs/book/v3/installation.md @@ -0,0 +1,5 @@ +# Installation + +Install dotkernel/dot-response-header by executing the following Composer command in your project directory: + + composer require dotkernel/dot-response-header diff --git a/docs/book/v3/overview.md b/docs/book/v3/overview.md new file mode 100644 index 0000000..56a80cc --- /dev/null +++ b/docs/book/v3/overview.md @@ -0,0 +1,3 @@ +# Overview + +`dot-response-header` is DotKernel's middleware for setting and overwriting custom response headers. diff --git a/docs/book/v3/usage.md b/docs/book/v3/usage.md new file mode 100644 index 0000000..131fe86 --- /dev/null +++ b/docs/book/v3/usage.md @@ -0,0 +1,24 @@ +# Usage + +Because headers are matched with route names, we can have custom response headers for every request, by defining new headers under the `*` key, in the configuration file `response-header.global.php`. + +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 + +```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/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..d9f0fae --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,19 @@ +docs_dir: docs/book +site_dir: docs/html +extra: + project: Packages + current_version: v3 + versions: + - v3 +nav: + - Home: index.md + - v3: + - Overview: v3/overview.md + - Installation: v3/installation.md + - Configuration: v3/configuration.md + - Usage: v3/usage.md +site_name: dot-response-header +site_description: "DotKernel's middleware for setting and overwriting custom response headers." +repo_url: "https://github.com/dotkernel/dot-response-header" +plugins: + - search