maxlzp / money
Php implementation of Money entity
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/maxlzp/money
Requires
- php: >=7.1.0
Requires (Dev)
- phpunit/phpunit: ~4.3
This package is auto-updated.
Last update: 2025-09-15 00:41:59 UTC
README
Create
$fiveCents = Money::USD(5); $oneEuro = Money::EUR(100);
Reset supported currencies
Create a class implementing CurrenciesSourceInterface:
class UpdatedCurrenciesSource implements CurrenciesSourceInterface { protected $data = [ 'USD' => [ 'name' => 'US Dollar', 'isoCode' => '840', ], ]; /** * Return CurrencyDto. Possibly from some storage/ * @param string $currencyCode * @return CurrencyDto * @throws CurrencyUnsupportedException */ public function getWithCode(string $currencyCode): CurrencyDto { if (\array_key_exists($currencyCode, $this->data)) { return new CurrencyDto( $currencyCode, $this->data[$currencyCode]['isoCode'], $this->data[$currencyCode]['name'] ); } throw new CurrencyUnsupportedException($currencyCode); } }
Reset currencies source at Currency class:
Currency::resetCurrenciesSource(new UpdatedCurrenciesSource());