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: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: vendor/bin/psalm --stats --no-progress --output-format=github --shepherd --threads=$(nproc)

- name: 'PHPStan'
run: vendor/bin/phpstan analyze --no-progress --error-format=github --ansi --configuration=phpstan.dist.neon ./
run: vendor/bin/phpstan analyze --no-progress --error-format=github --ansi --configuration=phpstan.dist.neon
steps:
- name: 'Checkout Code'
uses: actions/checkout@v4
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# PhdExceptionHandlerBundle

🧰 Provides [Symfony Messenger](https://symfony.com/doc/current/messenger.html) middlewares tailored for exception
handling. You can easily re-raise exceptions, chain them, or handle with a dedicated bus.
🧰 PHP Exception Handler built on top of [Symfony Messenger](https://symfony.com/doc/current/messenger.html) component.
Provides middlewares that allow you to easily re-raise exceptions, chain them, or handle with a dedicated handler.

[![Build Status](https://img.shields.io/github/actions/workflow/status/phphd/exception-handler-bundle/ci.yaml?branch=main)](https://github.com/phphd/exception-handler-bundle/actions?query=branch%3Amain)
[![Codecov](https://codecov.io/gh/phphd/exception-handler-bundle/graph/badge.svg?token=GZRXWYT55Z)](https://codecov.io/gh/phphd/exception-handler-bundle)
[![Psalm coverage](https://shepherd.dev/github/phphd/exception-handler-bundle/coverage.svg)](https://shepherd.dev/github/phphd/exception-handler-bundle)
[![Psalm level](https://shepherd.dev/github/phphd/exception-handler-bundle/level.svg)](https://shepherd.dev/github/phphd/exception-handler-bundle)
[![Packagist Downloads](https://img.shields.io/packagist/dt/phphd/exception-handler-bundle.svg)](https://packagist.org/packages/phphd/exception-handler-bundle)
[![Licence](https://img.shields.io/github/license/phphd/exception-handler-bundle.svg)](https://github.com/phphd/exception-handler-bundle/blob/main/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/phphd/exception-handler/ci.yaml?branch=main)](https://github.com/phphd/exception-handler/actions?query=branch%3Amain)
[![Codecov](https://codecov.io/gh/phphd/exception-handler/graph/badge.svg?token=GZRXWYT55Z)](https://codecov.io/gh/phphd/exception-handler)
[![Psalm coverage](https://shepherd.dev/github/phphd/exception-handler/coverage.svg)](https://shepherd.dev/github/phphd/exception-handler)
[![Psalm level](https://shepherd.dev/github/phphd/exception-handler/level.svg)](https://shepherd.dev/github/phphd/exception-handler)
[![Packagist Downloads](https://img.shields.io/packagist/dt/phphd/exception-handler.svg)](https://packagist.org/packages/phphd/exception-handler)
[![Licence](https://img.shields.io/github/license/phphd/exception-handler.svg)](https://github.com/phphd/exception-handler/blob/main/LICENSE)

## Installation 📥

1. Install via composer

```sh
composer require phphd/exception-handler-bundle
composer require phphd/exception-handler
```

2. Enable the bundle in the `bundles.php`

```php
PhPhD\ExceptionHandlerBundle\PhdExceptionHandlerBundle::class => ['all' => true],
PhPhD\ExceptionHandler\Bundle\PhdExceptionHandlerBundle::class => ['all' => true],
```

## Configuration ⚒️
Expand Down Expand Up @@ -88,7 +88,7 @@ Filters out all null results of exception handlers.
The simplest use-case is defining `#[RaiseAs]` attribute on your exception class:

```php
use PhPhD\ExceptionHandler\Chain\Escalator\RaiseAs;
use PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAs;

#[RaiseAs(AccessDeniedHttpException::class, bus: 'api.exception.bus')]
final class NonWhiteListedUserException extends DomainException
Expand All @@ -104,7 +104,7 @@ contexts (hence, different buses), it is required to explicitly specify the bus
must be raised, so that in other scenarios another exceptions could be escalated:

```php
use PhPhD\ExceptionHandler\Chain\Escalator\RaiseAs;
use PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAs;

#[RaiseAs(ImportLockedHttpException::class, bus: 'api.exception.bus')]
#[RaiseAs(RecoverableMessageHandlingException::class, bus: 'consumer.exception.bus')]
Expand Down
19 changes: 0 additions & 19 deletions Resources/config/services.yaml

This file was deleted.

35 changes: 19 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "phphd/exception-handler-bundle",
"name": "phphd/exception-handler",
"description": "Message Bus Exception Handler",
"type": "symfony-bundle",
"license": "MIT",
Expand All @@ -12,21 +12,28 @@
"minimum-stability": "stable",
"require": {
"php": ">=8.1",
"symfony/dependency-injection": "^6.0 | ^7.0",
"symfony/http-kernel": "^6.0 | ^7.0",
"symfony/messenger": "^6.2 | ^7.0",
"symfony/string": "^6.0 | ^7.0"
"symfony/string": "^6.0 | ^7.0",
"symfony/polyfill-php83": "^1.31"
},
"conflict": {
"symfony/http-kernel": "<6.0 || >=8.0",
"symfony/dependency-injection": "<6.0 || >=8.0",
"symfony/config": "<6.0 || >=8.0"
},
"require-dev": {
"tomasvotruba/type-coverage": "^0.2.3",
"symfony/http-kernel": "*",
"symfony/dependency-injection":"*",
"symfony/config": "*",
"tomasvotruba/type-coverage": "^1.0",
"phpstan/phpstan": "^1.10.60",
"vimeo/psalm": "^5.23.1",
"phpat/phpat": "^0.10.15",
"phpstan/phpstan-phpunit": "^1.3.16",
"vimeo/psalm": "^5.26.1",
"phpat/phpat": "^0.10.18",
"phpstan/phpstan-phpunit": "^1.4.0",
"psalm/plugin-phpunit": "^0.18.4",
"nyholm/symfony-bundle-test": "^3.0",
"phphd/coding-standard": "~0.5.0",
"phpunit/phpunit": "^10.5.13"
"phphd/coding-standard": "~0.5.3",
"phpunit/phpunit": "^10.5.36"
},
"repositories": [
{
Expand All @@ -35,17 +42,13 @@
}
],
"autoload": {
"classmap": [
"DependencyInjection",
"PhdExceptionHandlerBundle.php"
],
"psr-4": {
"PhPhD\\ExceptionHandler\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"PhPhD\\ExceptionHandlerBundle\\Tests\\": "tests"
"PhPhD\\ExceptionHandler\\Bundle\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -61,7 +64,7 @@
"ci:ecs-fix": "vendor/bin/ecs check --fix",
"ci:rector": "vendor/bin/rector process --dry-run -vv",
"ci:rector-fix": "vendor/bin/rector process",
"ci:phpstan": "vendor/bin/phpstan analyze ./",
"ci:phpstan": "vendor/bin/phpstan analyze",
"ci:psalm": "vendor/bin/psalm",
"ci:test": "vendor/bin/phpunit --testdox --colors=always",
"ci:unit-test": "vendor/bin/phpunit --testdox --colors=always --testsuite=Unit",
Expand Down
7 changes: 4 additions & 3 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ parameters:
level: 9
phpVersion: 80213
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
paths:
- src
- tests
excludePaths:
analyseAndScan:
- vendor
- tests/*/Stub/*
- rector.php
- ecs.php
type_coverage:
return_type: 100
param_type: 100
property_type: 100
constant: 0
fileExtensions:
- 'php'
phpat:
Expand Down
11 changes: 5 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory>tests/Integration</directory>
<directory suffix="IntegrationTest.php">src</directory>
</testsuite>
</testsuites>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>.</directory>
<directory>src</directory>
</include>
<exclude>
<directory>vendor</directory>
<directory>tests</directory>
<file>rector.php</file>
<file>ecs.php</file>
<directory>src/*/*/Tests</directory>
<directory>src/*/*/*/Tests</directory>
<directory>src/*/*/*/*/Tests</directory>
</exclude>
</source>
</phpunit>
3 changes: 1 addition & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
findUnusedCode="true"
>
<projectFiles>
<directory name="./"/>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
<file name="rector.php"/>
</ignoreFiles>
</projectFiles>
<plugins>
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
$rectorConfig->skip([
LocallyCalledStaticMethodToNonStaticRector::class => [
__DIR__.'/tests',
__DIR__.'/src/*/Tests/*.php',
],
]);
};
1 change: 1 addition & 0 deletions src/Bundle/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Tests export-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

declare(strict_types=1);

namespace PhPhD\ExceptionHandlerBundle\DependencyInjection;
namespace PhPhD\ExceptionHandler\Bundle\DependencyInjection;

use Exception;
use Override;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand All @@ -17,10 +18,9 @@ final class PhdExceptionHandlerExtension extends Extension
/**
* @param array<array-key,mixed> $configs
*
* @override
*
* @throws Exception
*/
#[Override]
public function load(array $configs, ContainerBuilder $container): void
{
/** @var ?string $env */
Expand All @@ -30,7 +30,7 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load(__DIR__.'/../Resources/config/services.yaml');
}

/** @override */
#[Override]
public function getAlias(): string
{
return self::ALIAS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

declare(strict_types=1);

namespace PhPhD\ExceptionHandlerBundle;
namespace PhPhD\ExceptionHandler\Bundle;

use PhPhD\ExceptionHandlerBundle\DependencyInjection\PhdExceptionHandlerExtension;
use Override;
use PhPhD\ExceptionHandler\Bundle\DependencyInjection\PhdExceptionHandlerExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/** @api */
final class PhdExceptionHandlerBundle extends Bundle
{
/** @override */
#[Override]
protected function createContainerExtension(): PhdExceptionHandlerExtension
{
return new PhdExceptionHandlerExtension();
Expand Down
2 changes: 2 additions & 0 deletions src/Bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports:
- { resource: '../../../{Handler,Middleware}/**/services.yaml' }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Compiler;
namespace PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware;
namespace PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware;

use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ framework:
middleware:
- add_bus_name_stamp_middleware: [ query.bus ]
- phd_exception_handler
- PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware
- PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware
- handle_message
query.exception.bus:
default_middleware: false
middleware:
- phd_exception_rethrow_unhandled
- phd_exception_chaining
- phd_exception_result_filter
- PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware
- PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware
- handle_message:
- true
command.bus:
default_middleware: false
middleware:
- phd_exception_handler
- PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware
- PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware
- handle_message
api.command.exception.bus:
default_middleware: false
middleware:
- phd_exception_rethrow_unhandled
- phd_exception_chaining
- phd_exception_result_filter
- PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware
- PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware
- handle_message:
- true
9 changes: 9 additions & 0 deletions src/Bundle/Tests/Bootstrap/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
PhPhD\ExceptionHandler\Bundle\Tests\Stub\MessageHandlerStub:
autoconfigure: true

PhPhD\ExceptionHandler\Bundle\Tests\Stub\LogExceptionMessageHandlerStub:
autoconfigure: true

PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware:
autoconfigure: true
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

declare(strict_types=1);

namespace PhPhD\ExceptionHandlerBundle\Tests\Integration;
namespace PhPhD\ExceptionHandler\Bundle\Tests;

use Nyholm\BundleTest\TestKernel;
use PhPhD\ExceptionHandlerBundle\PhdExceptionHandlerBundle;
use PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Compiler\TestServicesCompilerPass;
use PhPhD\ExceptionHandler\Bundle\PhdExceptionHandlerBundle;
use PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Compiler\TestServicesCompilerPass;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

abstract class TestCase extends KernelTestCase
abstract class BundleTestCase extends KernelTestCase
{
protected static function getKernelClass(): string
{
Expand Down
Loading
Loading