-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathTransactionRollback.php
More file actions
58 lines (48 loc) · 1.77 KB
/
Copy pathTransactionRollback.php
File metadata and controls
58 lines (48 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
/*
* This file is part of the Neo4j PHP Client and Driver package.
*
* (c) Nagels <https://nagels.tech>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Laudis\Neo4j\TestkitBackend\Handlers;
use Laudis\Neo4j\Contracts\TransactionInterface;
use Laudis\Neo4j\Exception\Neo4jException;
use Laudis\Neo4j\Exception\TransactionException;
use Laudis\Neo4j\TestkitBackend\Contracts\RequestHandlerInterface;
use Laudis\Neo4j\TestkitBackend\Contracts\TestkitResponseInterface;
use Laudis\Neo4j\TestkitBackend\MainRepository;
use Laudis\Neo4j\TestkitBackend\Requests\TransactionRollbackRequest;
use Laudis\Neo4j\TestkitBackend\Responses\BackendErrorResponse;
use Laudis\Neo4j\TestkitBackend\Responses\DriverErrorResponse;
use Laudis\Neo4j\TestkitBackend\Responses\TransactionResponse;
/**
* @implements RequestHandlerInterface<TransactionRollbackRequest>
*/
final class TransactionRollback implements RequestHandlerInterface
{
private MainRepository $repository;
public function __construct(MainRepository $repository)
{
$this->repository = $repository;
}
/**
* @param TransactionRollbackRequest $request
*/
public function handle($request): TestkitResponseInterface
{
$tsx = $this->repository->getTransaction($request->getTxId());
if ($tsx === null || !$tsx instanceof TransactionInterface) {
return new BackendErrorResponse('Transaction not found');
}
try {
$tsx->rollback();
} catch (Neo4jException|TransactionException $e) {
return new DriverErrorResponse($request->getTxId(), $e);
}
return new TransactionResponse($request->getTxId());
}
}