currency = $currency; $this->name = (string) $attributes['name']; $this->code = (int) $attributes['code']; $this->rate = (float) (isset($attributes['rate']) ? $attributes['rate'] : 1); $this->precision = (int) $attributes['precision']; $this->subunit = (int) $attributes['subunit']; $this->symbol = (string) $attributes['symbol']; $this->symbolFirst = (bool) $attributes['symbol_first']; $this->decimalMark = (string) $attributes['decimal_mark']; $this->thousandsSeparator = (string) $attributes['thousands_separator']; } public static function __callStatic(string $method, array $arguments): Currency { return new self($method); } /** * @return class-string */ public static function castUsing(array $arguments): string { return CurrencyCast::class; } public static function setCurrencies(array $currencies): void { static::$currencies = $currencies; } public static function getCurrencies(): array { return static::$currencies ??= require __DIR__ . '/../config/money.php'; } public function equals(Currency $currency): bool { return $this->getCurrency() === $currency->getCurrency(); } public function getCurrency(): string { return $this->currency; } public function getName(): string { return $this->name; } public function getCode(): int { return $this->code; } public function getRate(): float { return $this->rate; } public function getPrecision(): int { return $this->precision; } public function getSubunit(): int { return $this->subunit; } public function getSymbol(): string { return $this->symbol; } public function isSymbolFirst(): bool { return $this->symbolFirst; } public function getDecimalMark(): string { return $this->decimalMark; } public function getThousandsSeparator(): string { return $this->thousandsSeparator; } public function getPrefix(): string { if (!$this->symbolFirst) { return ''; } return $this->symbol; } public function getSuffix(): string { if ($this->symbolFirst) { return ''; } return ' ' . $this->symbol; } public function toArray(): array { return [$this->currency => [ 'name' => $this->name, 'code' => $this->code, 'rate' => $this->rate, 'precision' => $this->precision, 'subunit' => $this->subunit, 'symbol' => $this->symbol, 'symbol_first' => $this->symbolFirst, 'decimal_mark' => $this->decimalMark, 'thousands_separator' => $this->thousandsSeparator, 'prefix' => $this->getPrefix(), 'suffix' => $this->getSuffix(), ]]; } public function toJson($options = 0): string { return json_encode($this->toArray(), $options); } public function jsonSerialize(): array { return $this->toArray(); } public function render(): string { return $this->currency . ' (' . $this->name . ')'; } public function __toString(): string { return $this->render(); } }