-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
322 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Exceptions; | ||
|
||
use InvalidArgumentException; | ||
|
||
final class TransactionRollbackException extends InvalidArgumentException implements ExceptionInterface | ||
{ | ||
public function __construct( | ||
private mixed $result | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function getResult(): mixed | ||
{ | ||
return $this->result; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Listeners; | ||
|
||
use Bavix\Wallet\Internal\Service\ConnectionServiceInterface; | ||
use Bavix\Wallet\Services\RegulatorServiceInterface; | ||
|
||
final class TransactionBeginningListener | ||
{ | ||
public function __construct( | ||
private ConnectionServiceInterface $connectionService, | ||
private RegulatorServiceInterface $regulatorService | ||
) { | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
if ($this->connectionService->get()->transactionLevel() === 1) { | ||
$this->regulatorService->purge(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Listeners; | ||
|
||
use Bavix\Wallet\Internal\Service\ConnectionServiceInterface; | ||
use Bavix\Wallet\Services\RegulatorServiceInterface; | ||
|
||
final class TransactionCommittedListener | ||
{ | ||
public function __construct( | ||
private ConnectionServiceInterface $connectionService, | ||
private RegulatorServiceInterface $regulatorService | ||
) { | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
if ($this->connectionService->get()->transactionLevel() === 0) { | ||
$this->regulatorService->committed(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Listeners; | ||
|
||
use Bavix\Wallet\Internal\Service\ConnectionServiceInterface; | ||
use Bavix\Wallet\Services\RegulatorServiceInterface; | ||
|
||
final class TransactionCommittingListener | ||
{ | ||
public function __construct( | ||
private ConnectionServiceInterface $connectionService, | ||
private RegulatorServiceInterface $regulatorService | ||
) { | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
/** | ||
* In fact, this if is not needed here. | ||
* But in order to protect the code from changes in the framework, I added a check here. | ||
*/ | ||
if ($this->connectionService->get()->transactionLevel() === 1) { | ||
$this->regulatorService->committing(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Listeners; | ||
|
||
use Bavix\Wallet\Internal\Service\ConnectionServiceInterface; | ||
use Bavix\Wallet\Services\RegulatorServiceInterface; | ||
|
||
final class TransactionRolledBackListener | ||
{ | ||
public function __construct( | ||
private ConnectionServiceInterface $connectionService, | ||
private RegulatorServiceInterface $regulatorService | ||
) { | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
if ($this->connectionService->get()->transactionLevel() === 0) { | ||
$this->regulatorService->purge(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Service; | ||
|
||
use Illuminate\Database\ConnectionInterface; | ||
use Illuminate\Database\ConnectionResolverInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ConnectionService implements ConnectionServiceInterface | ||
{ | ||
private ConnectionInterface $connection; | ||
|
||
public function __construct(ConnectionResolverInterface $connectionResolver) | ||
{ | ||
$this->connection = $connectionResolver->connection(config('wallet.database.connection')); | ||
} | ||
|
||
public function get(): ConnectionInterface | ||
{ | ||
return $this->connection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bavix\Wallet\Internal\Service; | ||
|
||
use Illuminate\Database\ConnectionInterface; | ||
|
||
interface ConnectionServiceInterface | ||
{ | ||
public function get(): ConnectionInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.