Open Journal Systems  3.3.0
AggregateMoneyParser.php
1 <?php
2 
3 namespace Money\Parser;
4 
8 
14 final class AggregateMoneyParser implements MoneyParser
15 {
19  private $parsers = [];
20 
24  public function __construct(array $parsers)
25  {
26  if (empty($parsers)) {
27  throw new \InvalidArgumentException(sprintf('Initialize an empty %s is not possible', self::class));
28  }
29 
30  foreach ($parsers as $parser) {
31  if (false === $parser instanceof MoneyParser) {
32  throw new \InvalidArgumentException('All parsers must implement '.MoneyParser::class);
33  }
34 
35  $this->parsers[] = $parser;
36  }
37  }
38 
42  public function parse($money, $forceCurrency = null)
43  {
44  if ($forceCurrency !== null && !$forceCurrency instanceof Currency) {
45  @trigger_error('Passing a currency as string is deprecated since 3.1 and will be removed in 4.0. Please pass a '.Currency::class.' instance instead.', E_USER_DEPRECATED);
46  $forceCurrency = new Currency($forceCurrency);
47  }
48 
49  foreach ($this->parsers as $parser) {
50  try {
51  return $parser->parse($money, $forceCurrency);
52  } catch (Exception\ParserException $e) {
53  }
54  }
55 
56  throw new Exception\ParserException(sprintf('Unable to parse %s', $money));
57  }
58 }
Money\Exception
Definition: paymethod/paypal/vendor/moneyphp/money/src/Exception.php:10
Money\Parser\AggregateMoneyParser\__construct
__construct(array $parsers)
Definition: AggregateMoneyParser.php:27
Money\Parser\AggregateMoneyParser
Definition: AggregateMoneyParser.php:14
Money\Currency
Definition: vendor/moneyphp/money/src/Currency.php:14
Money\Exception
Definition: FormatterException.php:3
Money\Exception\ParserException
Definition: ParserException.php:12
Money\Parser
Definition: AggregateMoneyParser.php:3
Money\MoneyParser
Definition: MoneyParser.php:10
Money\Parser\AggregateMoneyParser\parse
parse($money, $forceCurrency=null)
Definition: AggregateMoneyParser.php:45
Currency
Basic class describing a currency.
Definition: Currency.inc.php:24