Skip to content

Commit b1c8bbc

Browse files
author
Babichev Maxim
committed
#103 disable proxy
1 parent a0305c0 commit b1c8bbc

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/Services/ProxyService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Bavix\Wallet\Services;
44

55
use ArrayAccess;
6+
use Bavix\Wallet\Interfaces\Storable;
67
use function array_key_exists;
78

89
/**
@@ -94,6 +95,7 @@ public function offsetUnset($offset): void
9495
*/
9596
public function fresh(): void
9697
{
98+
app()->instance(Storable::class, null);
9799
$this->data = [];
98100
}
99101

src/Simple/MemoryStore.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,35 @@
33
namespace Bavix\Wallet\Simple;
44

55
use Bavix\Wallet\Interfaces\Storable;
6-
use Bavix\Wallet\Services\ProxyService;
76
use Bavix\Wallet\Services\WalletService;
87

98
class MemoryStore implements Storable
109
{
1110

11+
/**
12+
* @var array
13+
*/
14+
protected $balanceSheets = [];
15+
1216
/**
1317
* @inheritDoc
1418
*/
1519
public function getBalance($object): int
1620
{
1721
$wallet = app(WalletService::class)->getWallet($object);
18-
$proxy = app(ProxyService::class);
19-
if (!$proxy->has($wallet->getKey())) {
20-
$proxy->set($wallet->getKey(), (int) $wallet->getOriginal('balance', 0));
22+
if (!\array_key_exists($wallet->getKey(), $this->balanceSheets)) {
23+
$this->balanceSheets[$wallet->getKey()] = (int) $wallet->getOriginal('balance', 0);
2124
}
2225

23-
return $proxy[$wallet->getKey()];
26+
return $this->balanceSheets[$wallet->getKey()];
2427
}
2528

2629
/**
2730
* @inheritDoc
2831
*/
2932
public function incBalance($object, int $amount): int
3033
{
31-
$wallet = app(WalletService::class)->getWallet($object);
32-
$proxy = app(ProxyService::class);
33-
$balance = $wallet->balance + $amount;
34-
35-
if ($proxy->has($wallet->getKey())) {
36-
$balance = $proxy->get($wallet->getKey()) + $amount;
37-
}
38-
34+
$balance = $this->getBalance($object) + $amount;
3935
$this->setBalance($object, $balance);
4036
return $balance;
4137
}
@@ -46,8 +42,8 @@ public function incBalance($object, int $amount): int
4642
public function setBalance($object, int $amount): bool
4743
{
4844
$wallet = app(WalletService::class)->getWallet($object);
49-
$proxy = app(ProxyService::class);
50-
return (bool)$proxy->set($wallet->getKey(), $amount);
45+
$this->balanceSheets[$wallet->getKey()] = $amount;
46+
return true;
5147
}
5248

5349
}

0 commit comments

Comments
 (0)