19 private $parsers = [];
26 if (empty($parsers)) {
27 throw new \InvalidArgumentException(sprintf(
'Initialize an empty %s is not possible', self::class));
30 foreach ($parsers as $parser) {
32 throw new \InvalidArgumentException(
'All parsers must implement '.MoneyParser::class);
35 $this->parsers[] = $parser;
42 public function parse($money, $forceCurrency =
null)
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);
49 foreach ($this->parsers as $parser) {
51 return $parser->parse($money, $forceCurrency);
56 throw new Exception\ParserException(sprintf(
'Unable to parse %s', $money));