PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / moneyphp / money / src / Currencies / CachedCurrencies.php
ameliabooking / vendor / moneyphp / money / src / Currencies Last commit date
AggregateCurrencies.php 2 years ago BitcoinCurrencies.php 2 years ago CachedCurrencies.php 2 years ago CurrencyList.php 2 years ago ISOCurrencies.php 2 years ago
CachedCurrencies.php
96 lines
1 <?php
2
3 namespace Money\Currencies;
4
5 use Cache\Taggable\TaggableItemInterface;
6 use Money\Currencies;
7 use Money\Currency;
8 use Psr\Cache\CacheItemPoolInterface;
9
10 /**
11 * Cache the result of currency checking.
12 *
13 * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
14 */
15 final class CachedCurrencies implements Currencies
16 {
17 /**
18 * @var Currencies
19 */
20 private $currencies;
21
22 /**
23 * @var CacheItemPoolInterface
24 */
25 private $pool;
26
27 public function __construct(Currencies $currencies, CacheItemPoolInterface $pool)
28 {
29 $this->currencies = $currencies;
30 $this->pool = $pool;
31 }
32
33 /**
34 * {@inheritdoc}
35 */
36 public function contains(Currency $currency)
37 {
38 $item = $this->pool->getItem('currency|availability|'.$currency->getCode());
39
40 if (false === $item->isHit()) {
41 $item->set($this->currencies->contains($currency));
42
43 if ($item instanceof TaggableItemInterface) {
44 $item->addTag('currency.availability');
45 }
46
47 $this->pool->save($item);
48 }
49
50 return $item->get();
51 }
52
53 /**
54 * {@inheritdoc}
55 */
56 public function subunitFor(Currency $currency)
57 {
58 $item = $this->pool->getItem('currency|subunit|'.$currency->getCode());
59
60 if (false === $item->isHit()) {
61 $item->set($this->currencies->subunitFor($currency));
62
63 if ($item instanceof TaggableItemInterface) {
64 $item->addTag('currency.subunit');
65 }
66
67 $this->pool->save($item);
68 }
69
70 return $item->get();
71 }
72
73 /**
74 * {@inheritdoc}
75 */
76 #[\ReturnTypeWillChange]
77 public function getIterator()
78 {
79 return new \CallbackFilterIterator(
80 $this->currencies->getIterator(),
81 function (Currency $currency) {
82 $item = $this->pool->getItem('currency|availability|'.$currency->getCode());
83 $item->set(true);
84
85 if ($item instanceof TaggableItemInterface) {
86 $item->addTag('currency.availability');
87 }
88
89 $this->pool->save($item);
90
91 return true;
92 }
93 );
94 }
95 }
96