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
2 changes: 2 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
php:
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: Checkout
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/docs-build.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
- push

name: Run PHPStan checks

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

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

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.2"
- "8.3"
- "8.4"
- "8.5"

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

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr

- 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@v4
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 with PHPStan
run: vendor/bin/phpstan analyse
3 changes: 3 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"backwardCompatibilityCheck": true
}
68 changes: 37 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# dot-errorhandler

Error Logging Handler for DotKernel
Error Logging Handler for Dotkernel

## Version History

| Branch | Release | Service Manager | Log style implementation | PHP Version |
|--------|----------|-------------------|--------------------------|------------------------------------------------------------------------------------------------------------------|
| 4.0 | < 4.1.0 | Service Manager 3 | Laminas Log style | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.0.1) |
| 3.0 | < 4.0.0 | Service Manager 3 | Laminas Log | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/3.4.1) |

## Documentation

Documentation is available at: https://docs.dotkernel.org/dot-errorhandler/

## Badges

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-errorhandler)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.0.0)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.0.1)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/network)
Expand All @@ -12,24 +25,27 @@ Error Logging Handler for DotKernel

[![Build Static](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.0/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)

[![SymfonyInsight](https://insight.symfony.com/projects/cf1f8d89-f230-4157-bc8b-7cce20c75454/big.svg)](https://insight.symfony.com/projects/cf1f8d89-f230-4157-bc8b-7cce20c75454)
[![PHPStan](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml)

## Adding the error handler

- Add the composer package:
- Add the Composer package.

`composer require dotkernel/dot-errorhandler`
```shell
composer require dotkernel/dot-errorhandler
```

- Add the config provider
- in `config/config.php` add `\Dot\ErrorHandler\ConfigProvider`
- in `config/pipeline.php` add `\Dot\ErrorHandler\ErrorHandlerInterface::class`
- the interface is used as an alias to keep all error handling related configurations in one file
- **IMPORTANT NOTE** there should be no other error handlers after this one (only before) because the other error handler will catch the error causing dot-errorhandler not to catch any error, we recommend using just one error handler unless you have an error-specific handler

- Configure the error handler as shown below
> If you need other error handlers, you should place them before DotErrorhandler in the pipeline; else it will not be able to catch errors.
> We recommend using just one error handler unless you have an error-specific handler.

config/autoload/error-handling.global.php
- Configure the error handler as shown below.

In `config/autoload/error-handling.global.php`:

```php
<?php
Expand All @@ -54,45 +70,35 @@ return [

A configuration example for the default logger can be found in `config/log.global.php.dist`.

When declaring the `ErrorHandlerInterface` alias you can choose whether to log or not:

- for logging use `LogErrorHandler`
- for the simple Zend Expressive handler user `ErrorHandler`
When configuring the error handler in your application, you can choose between two classes:

The class `Dot\ErrorHandler\ErrorHandler` is the same as the Zend Expressive error handling class
the only difference being the removal of the `final` statement for making extension possible.
- `Dot\ErrorHandler\LogErrorHandler`: for logging and displaying errors
- `Dot\ErrorHandler\ErrorHandler`: for displaying errors only

The class `Dot\ErrorHandler\LogErrorHandler` is `Dot\ErrorHandler\ErrorHandler` with
added logging support.

As a note: both `LogErrorHandler` and `ErrorHandler` have factories declared in the
package's `ConfigProvider`. If you need a custom ErrorHandler it must have a factory
declared in the config, as in the example.
> Both `LogErrorHandler` and `ErrorHandler` have factories declared in the package's `ConfigProvider`.
> If you need a custom ErrorHandler, it must have a factory declared in the config, as in the below example:

Example:

```php
<?php

use Dot\ErrorHandler\ErrorHandlerInterface;
use Custom\MyErrorHandler;
use Custom\MyErrorHandlerFactory;
declare(strict_types=1);

return [
'dependencies' => [
'dependencies' => [
'factories' => [
MyErrorHandler::class => MyCustomHandlerFactory::class,
\App\CustomErrorHandler::class => \App\CustomHandlerFactory::class,
],

'aliases' => [
ErrorHandlerInterface::class => MyErrorHandler::class,
]
\Dot\ErrorHandler\ErrorHandlerInterface::class => \App\CustomErrorHandler::class,
],

],
'dot-errorhandler' => [
'loggerEnabled' => true,
'logger' => 'dot-log.default_logger'
]
'logger' => 'dot-log.default_logger',
],
];
```

Expand Down
30 changes: 16 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"homepage": "https://github.com/dotkernel/dot-errorhandler",
"authors": [
{
"name": "DotKernel Team",
"name": "Dotkernel Team",
"email": "[email protected]"
}
],
Expand All @@ -26,19 +26,21 @@
}
},
"require": {
"php": "~8.2.0 || ~8.3.0",
"dotkernel/dot-log": "^4.0.2",
"laminas/laminas-diactoros": "^3.3",
"laminas/laminas-stratigility": "^3.11",
"mezzio/mezzio": "^3.19",
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
"dotkernel/dot-log": "^4.0.5",
"laminas/laminas-diactoros": "^3.8.0",
"laminas/laminas-stratigility": "^4.3.0",
"mezzio/mezzio": "^3.24",
"psr/http-message": "^1.0 || ^2.0",
"psr/http-server-middleware": "^1.0"
"psr/http-server-middleware": "^1.0",
"psr/log": "^3.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "^2.5",
"laminas/laminas-coding-standard": "^3.0",
"mikey179/vfsstream": "^1.6.7",
"phpunit/phpunit": "^10.5",
"vimeo/psalm": "^5.22"
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5"
},
"autoload": {
"psr-4": {
Expand All @@ -54,12 +56,12 @@
"scripts": {
"check": [
"@cs-check",
"@test"
"@test",
"@static-analysis"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"static-analysis": "psalm --shepherd --stats"
"static-analysis": "phpstan analyse --memory-limit 1G",
"test": "phpunit --colors=always"
}
}
6 changes: 3 additions & 3 deletions config/error-handling.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ return [
'dependencies' => [
'aliases' => [
ErrorHandlerInterface::class => LogErrorHandler::class,
]
],
],
'dot-errorhandler' => [
'loggerEnabled' => true,
'logger' => 'dot-log.default_logger'
]
'logger' => 'dot-log.default_logger',
],
];
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

76 changes: 0 additions & 76 deletions docs/book/v3/configuration.md

This file was deleted.

5 changes: 0 additions & 5 deletions docs/book/v3/installation.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/book/v3/overview.md

This file was deleted.

Loading