19 private $formatters = [];
26 if (empty($formatters)) {
27 throw new \InvalidArgumentException(sprintf(
'Initialize an empty %s is not possible', self::class));
30 foreach ($formatters as $currencyCode => $formatter) {
32 throw new \InvalidArgumentException(
'All formatters must implement '.MoneyFormatter::class);
35 $this->formatters[$currencyCode] = $formatter;
44 $currencyCode = $money->getCurrency()->getCode();
46 if (isset($this->formatters[$currencyCode])) {
47 return $this->formatters[$currencyCode]->format($money);
50 if (isset($this->formatters[
'*'])) {
51 return $this->formatters[
'*']->format($money);
54 throw new FormatterException(
'No formatter found for currency '.$currencyCode);