1: <?php
2: namespace Sotr\Crypto;
3:
4: /**
5: * This class represents the current
6: * balance of different currencies in
7: * a given user account.
8: */
9: class AccountBalance
10: {
11: /**
12: * The set of currencies and their
13: * related balance.
14: *
15: * @var array
16: */
17: private $balance;
18:
19: /**
20: * Constructs a new balance instance,
21: * optionally with the provided starting
22: * balance.
23: *
24: * @param array $balance
25: */
26: public function __construct(array $balance = [])
27: {
28: foreach ($balance as $currency => $value) {
29: $this->set($currency, $value);
30: }
31: }
32:
33: /**
34: * Returns the balance of the given
35: * currency.
36: *
37: * @param string $currency
38: * @return float
39: */
40: public function get($currency)
41: {
42: return isset($this->balance[$currency]) ? $this->balance[$currency] : null;
43: }
44:
45: /**
46: * Sets the balance of the given currency.
47: *
48: * @param string $currency
49: * @param float $value
50: */
51: public function set($currency, $value)
52: {
53: $this->balance[$currency] = $value;
54: }
55: }
56: