PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / vendor / moneyphp / money / src / Currencies / CachedCurrencies.php

CachedCurrencies.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at vendor/moneyphp/money/src/Currencies/CachedCurrencies.php

96 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 <[email protected]>
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