PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.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 2.3.2 All 256 releases
give / vendor / moneyphp / money / src / Currencies / AggregateCurrencies.php

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

78 lines 1.7 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 Money\Currencies;
6 use Money\Currency;
7 use Money\Exception\UnknownCurrencyException;
8
9 /**
10 * Aggregates several currency repositories.
11 *
12 * @author Márk Sági-Kazár <[email protected]>
13 */
14 final class AggregateCurrencies implements Currencies
15 {
16 /**
17 * @var Currencies[]
18 */
19 private $currencies;
20
21 /**
22 * @param Currencies[] $currencies
23 */
24 public function __construct(array $currencies)
25 {
26 foreach ($currencies as $c) {
27 if (false === $c instanceof Currencies) {
28 throw new \InvalidArgumentException('All currency repositories must implement '.Currencies::class);
29 }
30 }
31
32 $this->currencies = $currencies;
33 }
34
35 /**
36 * {@inheritdoc}
37 */
38 public function contains(Currency $currency)
39 {
40 foreach ($this->currencies as $currencies) {
41 if ($currencies->contains($currency)) {
42 return true;
43 }
44 }
45
46 return false;
47 }
48
49 /**
50 * {@inheritdoc}
51 */
52 public function subunitFor(Currency $currency)
53 {
54 foreach ($this->currencies as $currencies) {
55 if ($currencies->contains($currency)) {
56 return $currencies->subunitFor($currency);
57 }
58 }
59
60 throw new UnknownCurrencyException('Cannot find currency '.$currency->getCode());
61 }
62
63 /**
64 * {@inheritdoc}
65 */
66 #[\ReturnTypeWillChange]
67 public function getIterator()
68 {
69 $iterator = new \AppendIterator();
70
71 foreach ($this->currencies as $currencies) {
72 $iterator->append($currencies->getIterator());
73 }
74
75 return $iterator;
76 }
77 }
78