• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

unixslayer / event-store-symfony-bundle / 9181004745

21 May 2024 05:44PM UTC coverage: 93.939% (+3.4%) from 90.511%
9181004745

push

github

web-flow
supported versions (#94)

* supported versions
    - drop support for unmaintained versions
    - add support for php8.2/8.3 and symfony 7.0
* update copyrights
* run static analysis on latest stable version

7 of 8 new or added lines in 4 files covered. (87.5%)

527 of 561 relevant lines covered (93.94%)

117.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/src/Messenger/EventStoreTransactionMiddleware.php
1
<?php
2

3
/**
4
 * This file is part of prooph/event-store-symfony-bundle.
5
 * (c) 2014-2024 Alexander Miertsch <kontakt@codeliner.ws>
6
 * (c) 2015-2024 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Prooph\Bundle\EventStore\Messenger;
15

16
use Prooph\EventStore\TransactionalEventStore;
17
use Symfony\Component\Messenger\Envelope;
18
use Symfony\Component\Messenger\Exception\HandlerFailedException;
19
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
20
use Symfony\Component\Messenger\Middleware\StackInterface;
21
use Symfony\Component\Messenger\Stamp\HandledStamp;
22
use Throwable;
23

24
final class EventStoreTransactionMiddleware implements MiddlewareInterface
25
{
26
    private TransactionalEventStore $eventStore;
27

28
    public function __construct(TransactionalEventStore $eventStore)
29
    {
30
        $this->eventStore = $eventStore;
27✔
31
    }
32

33
    public function handle(Envelope $envelope, StackInterface $stack): Envelope
34
    {
35
        $this->eventStore->beginTransaction();
27✔
36

37
        try {
38
            $envelope = $stack->next()->handle($envelope, $stack);
27✔
39

40
            $this->eventStore->commit();
9✔
41
        } catch (Throwable $e) {
18✔
42
            $this->eventStore->rollback();
18✔
43

44
            if ($e instanceof HandlerFailedException) {
18✔
45
                $method = 'getWrappedExceptions';
9✔
46
                if (! \method_exists($e, $method)) {
9✔
NEW
47
                    $method = 'getNestedExceptions';
×
48
                }
49

50
                // Remove all HandledStamp from the envelope so the retry will execute all handlers again.
51
                // When a handler fails, the queries of allegedly successful previous handlers just got rolled back.
52
                throw new HandlerFailedException(
9✔
53
                    $e->getEnvelope()->withoutAll(HandledStamp::class),
9✔
54
                    $e->$method()
9✔
55
                );
9✔
56
            }
57

58
            throw $e;
9✔
59
        }
60

61
        return $envelope;
9✔
62
    }
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc