90 lines
1.9 KiB
PHP
90 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Generator for src/Traits/HasCurrencyConvenienceMethods.php.
|
|
*
|
|
* Re-running this script must produce byte-identical output. CI uses
|
|
* `composer check:currency-trait` to fail builds when the committed trait
|
|
* drifts from this generator.
|
|
*/
|
|
|
|
/**
|
|
* Currency code => factory method name.
|
|
*
|
|
* Keep the list in sync with the Mollie supported-currency list. Method names
|
|
* default to the lowercase ISO code; EUR is special-cased to `euro` for
|
|
* historical readability.
|
|
*/
|
|
$currencies = [
|
|
'AED' => 'aed',
|
|
'AUD' => 'aud',
|
|
'BGN' => 'bgn',
|
|
'BRL' => 'brl',
|
|
'CAD' => 'cad',
|
|
'CHF' => 'chf',
|
|
'CZK' => 'czk',
|
|
'DKK' => 'dkk',
|
|
'EUR' => 'euro',
|
|
'GBP' => 'gbp',
|
|
'HKD' => 'hkd',
|
|
'HUF' => 'huf',
|
|
'ILS' => 'ils',
|
|
'ISK' => 'isk',
|
|
'JPY' => 'jpy',
|
|
'MXN' => 'mxn',
|
|
'MYR' => 'myr',
|
|
'NOK' => 'nok',
|
|
'NZD' => 'nzd',
|
|
'PHP' => 'php',
|
|
'PLN' => 'pln',
|
|
'RON' => 'ron',
|
|
'RUB' => 'rub',
|
|
'SEK' => 'sek',
|
|
'SGD' => 'sgd',
|
|
'THB' => 'thb',
|
|
'TWD' => 'twd',
|
|
'USD' => 'usd',
|
|
'ZAR' => 'zar',
|
|
];
|
|
|
|
$methods = [];
|
|
foreach ($currencies as $code => $method) {
|
|
$methods[] = <<<PHP
|
|
/**
|
|
* Create a Money object for {$code} currency.
|
|
*
|
|
* @param string \$value The amount value (e.g., '10.00')
|
|
* @return self
|
|
*/
|
|
public static function {$method}(string \$value): self
|
|
{
|
|
return new static('{$code}', \$value);
|
|
}
|
|
PHP;
|
|
}
|
|
|
|
$body = implode("\n\n", $methods);
|
|
|
|
$contents = <<<PHP
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
// AUTO-GENERATED BY tools/generate-currency-trait.php — DO NOT EDIT MANUALLY. Run: php tools/generate-currency-trait.php
|
|
|
|
namespace Mollie\Api\Traits;
|
|
|
|
trait HasCurrencyConvenienceMethods
|
|
{
|
|
{$body}
|
|
}
|
|
|
|
PHP;
|
|
|
|
$target = dirname(__DIR__) . '/src/Traits/HasCurrencyConvenienceMethods.php';
|
|
file_put_contents($target, $contents);
|
|
|
|
fwrite(STDOUT, "Generated {$target} (" . count($currencies) . " currencies)\n");
|