33namespace Bavix \Wallet \Simple ;
44
55use Bavix \Wallet \Interfaces \Storable ;
6- use Bavix \Wallet \Services \ProxyService ;
76use Bavix \Wallet \Services \WalletService ;
87
98class 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