Skip to content

Commit 9b84fdc

Browse files
committed
ExtraDtoInterface
1 parent 5b59ae2 commit 9b84fdc

23 files changed

+380
-29
lines changed

config/config.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Bavix\Wallet\Internal\Assembler\AvailabilityDtoAssembler;
66
use Bavix\Wallet\Internal\Assembler\BalanceUpdatedEventAssembler;
7+
use Bavix\Wallet\Internal\Assembler\ExtraDtoAssembler;
8+
use Bavix\Wallet\Internal\Assembler\OptionDtoAssembler;
79
use Bavix\Wallet\Internal\Assembler\TransactionDtoAssembler;
810
use Bavix\Wallet\Internal\Assembler\TransactionQueryAssembler;
911
use Bavix\Wallet\Internal\Assembler\TransferDtoAssembler;
@@ -126,6 +128,8 @@
126128
'assemblers' => [
127129
'availability' => AvailabilityDtoAssembler::class,
128130
'balance_updated_event' => BalanceUpdatedEventAssembler::class,
131+
'extra' => ExtraDtoAssembler::class,
132+
'option' => OptionDtoAssembler::class,
129133
'transaction' => TransactionDtoAssembler::class,
130134
'transfer_lazy' => TransferLazyDtoAssembler::class,
131135
'transfer' => TransferDtoAssembler::class,

src/Interfaces/Exchangeable.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Bavix\Wallet\Exceptions\BalanceIsEmpty;
88
use Bavix\Wallet\Exceptions\InsufficientFunds;
9+
use Bavix\Wallet\Internal\Dto\ExtraDtoInterface;
910
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
1011
use Bavix\Wallet\Internal\Exceptions\LockProviderNotFoundException;
1112
use Bavix\Wallet\Internal\Exceptions\RecordNotFoundException;
@@ -26,12 +27,12 @@ interface Exchangeable
2627
* @throws TransactionFailedException
2728
* @throws ExceptionInterface
2829
*/
29-
public function exchange(Wallet $to, $amount, ?array $meta = null): Transfer;
30+
public function exchange(Wallet $to, $amount, array|ExtraDtoInterface|null $meta = null): Transfer;
3031

3132
/**
3233
* @param int|string $amount
3334
*/
34-
public function safeExchange(Wallet $to, $amount, ?array $meta = null): ?Transfer;
35+
public function safeExchange(Wallet $to, $amount, array|ExtraDtoInterface|null $meta = null): ?Transfer;
3536

3637
/**
3738
* @param int|string $amount
@@ -42,5 +43,5 @@ public function safeExchange(Wallet $to, $amount, ?array $meta = null): ?Transfe
4243
* @throws TransactionFailedException
4344
* @throws ExceptionInterface
4445
*/
45-
public function forceExchange(Wallet $to, $amount, ?array $meta = null): Transfer;
46+
public function forceExchange(Wallet $to, $amount, array|ExtraDtoInterface|null $meta = null): Transfer;
4647
}

src/Interfaces/Wallet.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Bavix\Wallet\Exceptions\AmountInvalid;
88
use Bavix\Wallet\Exceptions\BalanceIsEmpty;
99
use Bavix\Wallet\Exceptions\InsufficientFunds;
10+
use Bavix\Wallet\Internal\Dto\ExtraDtoInterface;
1011
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
1112
use Bavix\Wallet\Internal\Exceptions\LockProviderNotFoundException;
1213
use Bavix\Wallet\Internal\Exceptions\TransactionFailedException;
@@ -64,12 +65,12 @@ public function forceWithdraw($amount, ?array $meta = null, bool $confirmed = tr
6465
* @throws TransactionFailedException
6566
* @throws ExceptionInterface
6667
*/
67-
public function transfer(self $wallet, $amount, ?array $meta = null): Transfer;
68+
public function transfer(self $wallet, $amount, array|null|ExtraDtoInterface $meta = null): Transfer;
6869

6970
/**
7071
* @param int|string $amount
7172
*/
72-
public function safeTransfer(self $wallet, $amount, ?array $meta = null): ?Transfer;
73+
public function safeTransfer(self $wallet, $amount, array|null|ExtraDtoInterface $meta = null): ?Transfer;
7374

7475
/**
7576
* @param int|string $amount
@@ -80,7 +81,7 @@ public function safeTransfer(self $wallet, $amount, ?array $meta = null): ?Trans
8081
* @throws TransactionFailedException
8182
* @throws ExceptionInterface
8283
*/
83-
public function forceTransfer(self $wallet, $amount, ?array $meta = null): Transfer;
84+
public function forceTransfer(self $wallet, $amount, array|null|ExtraDtoInterface $meta = null): Transfer;
8485

8586
/**
8687
* @param int|string $amount

src/Interfaces/WalletFloat.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Bavix\Wallet\Exceptions\AmountInvalid;
88
use Bavix\Wallet\Exceptions\BalanceIsEmpty;
99
use Bavix\Wallet\Exceptions\InsufficientFunds;
10+
use Bavix\Wallet\Internal\Dto\ExtraDtoInterface;
1011
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
1112
use Bavix\Wallet\Internal\Exceptions\LockProviderNotFoundException;
1213
use Bavix\Wallet\Internal\Exceptions\TransactionFailedException;
@@ -62,12 +63,12 @@ public function forceWithdrawFloat($amount, ?array $meta = null, bool $confirmed
6263
* @throws TransactionFailedException
6364
* @throws ExceptionInterface
6465
*/
65-
public function transferFloat(Wallet $wallet, $amount, ?array $meta = null): Transfer;
66+
public function transferFloat(Wallet $wallet, $amount, array|ExtraDtoInterface|null $meta = null): Transfer;
6667

6768
/**
6869
* @param float|string $amount
6970
*/
70-
public function safeTransferFloat(Wallet $wallet, $amount, ?array $meta = null): ?Transfer;
71+
public function safeTransferFloat(Wallet $wallet, $amount, array|ExtraDtoInterface|null $meta = null): ?Transfer;
7172

7273
/**
7374
* @param float|string $amount
@@ -78,7 +79,7 @@ public function safeTransferFloat(Wallet $wallet, $amount, ?array $meta = null):
7879
* @throws TransactionFailedException
7980
* @throws ExceptionInterface
8081
*/
81-
public function forceTransferFloat(Wallet $wallet, $amount, ?array $meta = null): Transfer;
82+
public function forceTransferFloat(Wallet $wallet, $amount, array|ExtraDtoInterface|null $meta = null): Transfer;
8283

8384
/**
8485
* @param float|string $amount
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Internal\Assembler;
6+
7+
use Bavix\Wallet\Internal\Dto\ExtraDto;
8+
use Bavix\Wallet\Internal\Dto\ExtraDtoInterface;
9+
10+
final class ExtraDtoAssembler implements ExtraDtoAssemblerInterface
11+
{
12+
public function __construct(private OptionDtoAssemblerInterface $optionDtoAssembler)
13+
{
14+
}
15+
16+
public function create(ExtraDtoInterface|array|null $data): ExtraDtoInterface
17+
{
18+
if ($data instanceof ExtraDtoInterface) {
19+
return $data;
20+
}
21+
22+
$option = $this->optionDtoAssembler->create($data);
23+
24+
return new ExtraDto($option, $option);
25+
}
26+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Internal\Assembler;
6+
7+
use Bavix\Wallet\Internal\Dto\ExtraDtoInterface;
8+
9+
interface ExtraDtoAssemblerInterface
10+
{
11+
public function create(array|ExtraDtoInterface|null $data): ExtraDtoInterface;
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Internal\Assembler;
6+
7+
use Bavix\Wallet\Internal\Dto\OptionDto;
8+
use Bavix\Wallet\Internal\Dto\OptionDtoInterface;
9+
10+
final class OptionDtoAssembler implements OptionDtoAssemblerInterface
11+
{
12+
public function create(array|null $data): OptionDtoInterface
13+
{
14+
return new OptionDto($data);
15+
}
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Internal\Assembler;
6+
7+
use Bavix\Wallet\Internal\Dto\OptionDtoInterface;
8+
9+
interface OptionDtoAssemblerInterface
10+
{
11+
public function create(array|null $data): OptionDtoInterface;
12+
}

src/Internal/Dto/ExtraDto.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Internal\Dto;
6+
7+
/** @internal */
8+
final class ExtraDto implements ExtraDtoInterface
9+
{
10+
public function __construct(
11+
private OptionDtoInterface $deposit,
12+
private OptionDtoInterface $withdraw
13+
) {
14+
}
15+
16+
public function getDepositExtra(): OptionDtoInterface
17+
{
18+
return $this->deposit;
19+
}
20+
21+
public function getWithdrawExtra(): OptionDtoInterface
22+
{
23+
return $this->withdraw;
24+
}
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Internal\Dto;
6+
7+
interface ExtraDtoInterface
8+
{
9+
public function getDepositExtra(): OptionDtoInterface;
10+
11+
public function getWithdrawExtra(): OptionDtoInterface;
12+
}

0 commit comments

Comments
 (0)