Skip to content

Commit 057960f

Browse files
authored
Merge pull request #70 from dotkernel/issue-69
Issue #69: V5 release updates
2 parents 3f5c5be + 40d9945 commit 057960f

19 files changed

Lines changed: 961 additions & 40 deletions

.github/workflows/codecov.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
steps:
2424
- name: Checkout
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@v7
2626

2727
- name: Install PHP
2828
uses: shivammathur/setup-php@v2
@@ -36,7 +36,7 @@ jobs:
3636
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
3737

3838
- name: Cache dependencies installed with composer
39-
uses: actions/cache@v3
39+
uses: actions/cache@v6
4040
with:
4141
path: ${{ env.COMPOSER_CACHE_DIR }}
4242
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
@@ -50,6 +50,6 @@ jobs:
5050
run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml
5151

5252
- name: Send code coverage report to Codecov.io
53-
uses: codecov/codecov-action@v3
53+
uses: codecov/codecov-action@v7
5454
with:
5555
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/static-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
steps:
2424
- name: Checkout
25-
uses: actions/checkout@v4
25+
uses: actions/checkout@v7
2626

2727
- name: Install PHP
2828
uses: shivammathur/setup-php@v2
@@ -36,7 +36,7 @@ jobs:
3636
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
3737

3838
- name: Cache dependencies installed with composer
39-
uses: actions/cache@v4
39+
uses: actions/cache@v6
4040
with:
4141
path: ${{ env.COMPOSER_CACHE_DIR }}
4242
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
@@ -47,4 +47,4 @@ jobs:
4747
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
4848

4949
- name: Run static analysis with PHPStan
50-
run: vendor/bin/phpstan analyse
50+
run: vendor/bin/phpstan analyse

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ dot-errorhandler is Dotkernel's PSR-15 compliant error handler.
44

55
## Version History
66

7-
| Branch | Release | PSR-11 | Log Style Implementation | OSS Lifecycle | PHP Version |
8-
|--------|----------|--------|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
9-
| 4.1 | `>= 4.2` | 2 | PSR-Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.1%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.4.1) |
10-
| 4.1 | `< 4.2` | 2 | Laminas Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.1%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.1.1) |
11-
| 4.0 | `< 4.1` | 1 | Laminas Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.0.2) |
12-
| 3.0 | `< 4.0` | 1 | Laminas Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F3.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/3.4.1) |
7+
| Branch | Release | PSR-11 | Log Style Implementation | OSS Lifecycle | PHP Version |
8+
|--------|----------|--------|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
9+
| 5.0 | `>= 5.0` | 2 | PSR-Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F5.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/5.0.0) |
10+
| 4.1 | `>= 4.2` | 2 | PSR-Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.1%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.4.1) |
11+
| 4.1 | `< 4.2` | 2 | Laminas Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.1%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.1.1) |
12+
| 4.0 | `< 4.1` | 1 | Laminas Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.0.2) |
13+
| 3.0 | `< 4.0` | 1 | Laminas Log | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F3.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/3.4.1) |
1314

1415
## Documentation
1516

@@ -18,16 +19,16 @@ Documentation is available at: https://docs.dotkernel.org/dot-errorhandler/
1819
## Badges
1920

2021
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-errorhandler)
21-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.4.0)
22+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/5.0.0)
2223

2324
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/issues)
2425
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/network)
2526
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/stargazers)
26-
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/blob/4.1/LICENSE)
27+
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/blob/5.0/LICENSE)
2728

28-
[![Build Static](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml/badge.svg?branch=4.1)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml)
29-
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.1/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
30-
[![PHPStan](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml/badge.svg?branch=4.1)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml)
29+
[![Build Static](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml)
30+
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/5.0/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
31+
[![PHPStan](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml)
3132

3233
## Adding the error handler
3334

SECURITY.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
| Version | Supported | PHP Version |
66
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
7+
| 5.0 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F5.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/5.0.0) |
78
| 4.1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.1%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.4.1) |
89
| 4.1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.1%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.1.1) |
910
| 4.0 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-errorhandler%2Fblob%2F4.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.0.2) |
@@ -12,28 +13,21 @@
1213

1314
## Reporting Potential Security Issues
1415

15-
If you have encountered a potential security vulnerability in this project,
16-
please report it to us at <security@dotkernel.com>. We will work with you to
17-
verify the vulnerability and patch it.
16+
If you have encountered a potential security vulnerability in this project, please report it to us at <security@dotkernel.com>.
17+
We will work with you to verify the vulnerability and patch it.
1818

1919
When reporting issues, please provide the following information:
2020

2121
- Component(s) affected
2222
- A description indicating how to reproduce the issue
2323
- A summary of the security vulnerability and impact
2424

25-
We request that you contact us via the email address above and give the
26-
project contributors a chance to resolve the vulnerability and issue a new
27-
release prior to any public exposure; this helps protect the project's
28-
users, and provides them with a chance to upgrade and/or update in order to
29-
protect their applications.
25+
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;
26+
this helps protect the project's users and provides them with a chance to upgrade and/or update to protect their applications.
3027

3128
## Policy
3229

3330
If we verify a reported security vulnerability, our policy is:
3431

35-
- We will patch the current release branch, as well as the immediate prior minor
36-
release branch.
37-
38-
- After patching the release branches, we will immediately issue new security
39-
fix releases for each patched release branch.
32+
- We will patch the current release branch, as well as the immediate prior minor release branch.
33+
- After patching the release branches, we will immediately issue new security fix releases for each patched release branch.

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
},
2424
"require": {
2525
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
26-
"dotkernel/dot-log": "^5.0",
26+
"dotkernel/dot-log": "^5.3",
2727
"laminas/laminas-diactoros": "^3.8.0",
2828
"laminas/laminas-stdlib": "^3.21",
29-
"laminas/laminas-stratigility": "^3.0 || ^4.0",
30-
"mezzio/mezzio": "^3.19",
29+
"laminas/laminas-stratigility": "^3.0 || ^4.3.1",
30+
"mezzio/mezzio": "^3.28.1",
3131
"psr/http-message": "^1.0 || ^2.0",
3232
"psr/http-server-middleware": "^1.0.2"
3333
},
3434
"require-dev": {
35-
"laminas/laminas-coding-standard": "^3.0.1",
35+
"laminas/laminas-coding-standard": "^3.1.0",
3636
"mikey179/vfsstream": "^1.6.12",
37-
"phpstan/phpstan": "^2.1",
38-
"phpstan/phpstan-phpunit": "^2.0",
39-
"phpunit/phpunit": "^10.5.45"
37+
"phpstan/phpstan": "^2.2.5",
38+
"phpstan/phpstan-phpunit": "^2.0.18",
39+
"phpunit/phpunit": "^10.5.64"
4040
},
4141
"autoload": {
4242
"psr-4": {

docs/book/v5/configuration.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Configuration
2+
3+
Register `dot-errorhandler` in your project by adding `Dot\ErrorHandler\ConfigProvider::class` to your configuration aggregator (to `config/config.php` for example), and add `\Dot\ErrorHandler\ErrorHandlerInterface::class` (to `config/pipeline.php` for example) **as the outermost layer of the middleware** to catch all exceptions.
4+
5+
Configure the error handler as shown below.
6+
7+
In **config/autoload/error-handling.global.php**:
8+
9+
```php
10+
<?php
11+
12+
declare(strict_types=1);
13+
14+
use Dot\ErrorHandler\ErrorHandlerInterface;
15+
use Dot\ErrorHandler\LogErrorHandler;
16+
17+
return [
18+
'dependencies' => [
19+
'aliases' => [
20+
ErrorHandlerInterface::class => LogErrorHandler::class,
21+
],
22+
],
23+
'dot-errorhandler' => [
24+
'loggerEnabled' => true,
25+
'logger' => 'dot-log.default_logger',
26+
]
27+
];
28+
```
29+
30+
A configuration example for the default logger can be found in `config/log.global.php.dist`.
31+
32+
When configuring the error handler in your application, you can choose between two classes:
33+
34+
- `Dot\ErrorHandler\LogErrorHandler`: for logging and displaying errors
35+
- `Dot\ErrorHandler\ErrorHandler`: for displaying errors only
36+
37+
> Both `LogErrorHandler` and `ErrorHandler` have factories declared in the package's `ConfigProvider`.
38+
> If you need a custom ErrorHandler, it must have a factory declared in the config, as in the below example:
39+
40+
```php
41+
<?php
42+
43+
declare(strict_types=1);
44+
45+
return [
46+
'dependencies' => [
47+
'factories' => [
48+
\App\CustomErrorHandler::class => \App\CustomHandlerFactory::class,
49+
],
50+
'aliases' => [
51+
\Dot\ErrorHandler\ErrorHandlerInterface::class => \App\CustomErrorHandler::class,
52+
],
53+
],
54+
'dot-errorhandler' => [
55+
'loggerEnabled' => true,
56+
'logger' => 'dot-log.default_logger',
57+
],
58+
];
59+
```
60+
61+
Config examples can be found in this project's `config` directory.

docs/book/v5/extra/cookie.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Log cookie data
2+
3+
Looking at `dot-errorhandler`'s config file, the array found at `CookieProvider::class` allows you to configure the behavior of this provider:
4+
5+
- **enabled**: enabled/disable this provider
6+
- **processor**: an array configuring the data processor to be used by the **CookieProvider**:
7+
- **class**: data processor class implementing `Dot\ErrorHandler\Extra\Processor\ProcessorInterface`
8+
- **replacementStrategy**: whether to replace specific cookie values completely or partially
9+
- **sensitiveParameters**: an array of cookie names that may contain sensitive information so their value should be masked partially/completely
10+
11+
## Configure provider
12+
13+
By default, **CookieProvider** is disabled.
14+
It can be enabled only by setting **enabled** to **true**.
15+
16+
If **enabled** is set to **true**, your log file will contain an additional field under the `extra` key, called `cookie`.
17+
If **enabled** is set to **false**, no additional field is added under the `extra` key.
18+
19+
## Configure processor
20+
21+
From here, we assume that **enabled** is set to **true**.
22+
23+
If **processor** is missing/empty, the processor is ignored; the provider will log the raw data available.
24+
If **processor** is specified, but **class** is missing/invalid, the processor is ignored and the provider will log the raw data available.
25+
26+
From here, we assume that **processor**.**class** is valid.
27+
28+
### Replacement strategy
29+
30+
This value should be an instance of `Dot\ErrorHandler\Extra\ReplacementStrategy`.
31+
32+
If **replacementStrategy** is missing/invalid, the default **replacementStrategy** is used, which is `ReplacementStrategy::Full`.
33+
Else, the value used should be one of:
34+
35+
- `ReplacementStrategy::Partial` for half-string replacements (e.g.: "abcdef" becomes "abc***")
36+
- `ReplacementStrategy::Full` for full-string replacements (e.g.: "abcdef" becomes "******")
37+
38+
### Sensitive parameters
39+
40+
If **sensitiveParameters** is missing/empty, the processor is ignored; the provider will log the raw data available.
41+
This is because without a set of **sensitiveParameters**, the processor is unable to determine which key needs to be processed or left untouched.
42+
When specifying the array of **sensitiveParameters**, there are two possibilities:
43+
44+
- use the constant `ProcessorInterface::ALL`, meaning alter all cookie values using the strategy specified by the **replacementStrategy**
45+
46+
```php
47+
'sensitiveParameters' => [
48+
Dot\ErrorHandler\Extra\Processor\ProcessorInterface::ALL,
49+
],
50+
```
51+
52+
- use exact strings to list the cookies for which the values should be altered using the strategy specified by the **replacementStrategy**
53+
54+
```php
55+
'sensitiveParameters' => [
56+
'rememberMe',
57+
],
58+
```
59+
60+
> **CookieProcessor** uses EXACT cookie name lookups.
61+
> To alter the value of a cookie, you need to specify the exact cookie name.
62+
63+
> The config `sensitiveParameters` is case-insensitive.
64+
65+
## Why should I use a processor
66+
67+
Consider the following request cookies:
68+
69+
```text
70+
[
71+
"sessionId" => "feb21b39f9c54e3a49af1f862acc8300",
72+
"language" => "en",
73+
]
74+
```
75+
76+
Without a **CookieProcessor**, the plain text session cookie identifier would end up saved in the log file:
77+
78+
```text
79+
..."extra":{"file":"/path/to/some/class.php","line":314,"cookie":{"sessionId":"feb21b39f9c54e3a49af1f862acc8300","language":"en"},...
80+
```
81+
82+
But with a properly configured **CookieProcessor**:
83+
84+
```php
85+
'processor' => [
86+
'class' => CookieProcessor::class,
87+
'replacementStrategy' => ReplacementStrategy::Full,
88+
'sensitiveParameters' => [
89+
'sessionId',
90+
],
91+
],
92+
```
93+
94+
the logged cookie data becomes:
95+
96+
```text
97+
..."extra":{"file":"/path/to/some/class.php","line":314,"cookie":{"sessionId":"********************************","language":"en"},...
98+
```
99+
100+
## Custom processor
101+
102+
If the existing processor does not offer enough features, you can create a custom processor.
103+
The custom processor must implement `Dot\ErrorHandler\Extra\Processor\ProcessorInterface` or extend `Dot\ErrorHandler\Extra\Processor\AbstractProcessor`, which already implements `Dot\ErrorHandler\Extra\Processor\ProcessorInterface`.
104+
Once the custom processor is ready, you need to configure **CookieProvider** to use it.
105+
For this, open `dot-errorhandler`'s config file and - under **CookieProvider::class** - set **processor**.**class** to the class string of your custom processor:
106+
107+
```php
108+
CookieProvider::class => [
109+
'enabled' => false,
110+
'processor' => [
111+
'class' => CustomCookieProcessor::class,
112+
'replacementStrategy' => ReplacementStrategy::Full,
113+
'sensitiveParameters' => [
114+
ProcessorInterface::ALL,
115+
],
116+
],
117+
],
118+
```
119+
120+
Using this, cookie data will be processed by `CustomCookieProcessor` and logged as provided by this new processor.

0 commit comments

Comments
 (0)