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 e73dfcf..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 update --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 e9de91d..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 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 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 41c5683..4b058e6 100644 --- a/README.md +++ b/README.md @@ -15,23 +15,22 @@ Logging Error Handler for DotKernel [![SymfonyInsight](https://insight.symfony.com/projects/cf1f8d89-f230-4157-bc8b-7cce20c75454/big.svg)](https://insight.symfony.com/projects/cf1f8d89-f230-4157-bc8b-7cce20c75454) - ## Adding the error handler -* Add the composer package: +- Add the composer package: + +`composer require dotkernel/dot-errorhandler` -`composer require dotkernel/dot-errorhandler:^3.1` +- 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 -* 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 +config/autoload/error-handling.global.php -configs/autoload/error-handling.global.php ```php . 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 6ebfaeb..15e0a6e 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,8 @@ }, "require-dev": { "laminas/laminas-coding-standard": "^2.5", - "mikey179/vfsstream": "^1.6", - "phpunit/phpunit": "^10.0", + "mikey179/vfsstream": "^1.6.7", + "phpunit/phpunit": "^10.5", "vimeo/psalm": "^5.22" }, "autoload": { diff --git a/docs/book/index.md b/docs/book/index.md new file mode 100644 index 0000000..fe84005 --- /dev/null +++ b/docs/book/index.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/docs/book/v3/configuration.md b/docs/book/v3/configuration.md new file mode 100644 index 0000000..ae1f365 --- /dev/null +++ b/docs/book/v3/configuration.md @@ -0,0 +1,76 @@ +# Configuration + +Register `dot-errorhandler` in you 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 + +- Configure the error handler as shown below + +config/autoload/error-handling.global.php + +```php + [ + 'aliases' => [ + ErrorHandlerInterface::class => LogErrorHandler::class, + ] + + ], + 'dot-errorhandler' => [ + 'loggerEnabled' => true, + 'logger' => 'dot-log.default_logger' + ] +]; +``` + +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 the simple Zend Expressive handler user `ErrorHandler` +- for logging use `LogErrorHandler` + +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. + +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. + +Example: + +```php + [ + 'factories' => [ + MyErrorHandler::class => MyCustomHandlerFactory::class, + ], + + 'aliases' => [ + ErrorHandlerInterface::class => MyErrorHandler::class, + ] + + ], + 'dot-errorhandler' => [ + 'loggerEnabled' => true, + 'logger' => 'dot-log.default_logger' + ] +]; +``` + +Config examples can be found in this project's `config` directory. diff --git a/docs/book/v3/installation.md b/docs/book/v3/installation.md new file mode 100644 index 0000000..723581c --- /dev/null +++ b/docs/book/v3/installation.md @@ -0,0 +1,5 @@ +# Installation + +Install `dotkernel/dot-errorhandler` by executing the following Composer command: + + composer require dotkernel/dot-errorhandler diff --git a/docs/book/v3/overview.md b/docs/book/v3/overview.md new file mode 100644 index 0000000..c124631 --- /dev/null +++ b/docs/book/v3/overview.md @@ -0,0 +1,6 @@ +# Overview + +`dot-errorhandler` is DotKernel's logging error handler, providing two options: + +- `Dot\ErrorHandler\ErrorHandler`, same as the Zend Expressive error handling class with the only difference being the removal of the `final` statement for making extension possible +- `Dot\ErrorHandler\LogErrorHandler` adds logging support to the default `ErrorHandler` class diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..e744b94 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,18 @@ +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 +site_name: dot-errorhandler +site_description: "DotKernel's logging error handler" +repo_url: "https://github.com/dotkernel/dot-errorhandler" +plugins: + - search diff --git a/test/LogErrorHandlerTest.php b/test/LogErrorHandlerTest.php index 73fa3a0..477d46e 100644 --- a/test/LogErrorHandlerTest.php +++ b/test/LogErrorHandlerTest.php @@ -34,6 +34,8 @@ class LogErrorHandlerTest extends TestCase private ResponseInterface|MockObject $response; /** @var callable():ResponseInterface $responseFactory */ private $responseFactory; + private StreamInterface|MockObject $body; + private RequestHandlerInterface|MockObject $handler; private Throwable|MockObject $exception; private ErrorResponseGenerator $errorResponseGenerator; private vfsStreamDirectory $fileSystem;